-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataPreparation.py
More file actions
32 lines (25 loc) · 1.16 KB
/
DataPreparation.py
File metadata and controls
32 lines (25 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import pandas as pd
def prepareData():
# Get all pokemon names in the pokeAPI dataset
response = requests.get("https://pokeapi.co/api/v2/pokemon?limit=500")
data = response.json()
pokemonNames = []
for value in data['results']:
pokemonNames.append(value['name'])
#Normalising the tables, as it is 1:m relation between pokemon and its type.
table_1 = []
table_2 = []
for name in pokemonNames:
response = (requests.get("https://pokeapi.co/api/v2/pokemon/{name}".format(name = name))).json()
height = response['height']
weight = response['weight']
bmi = round(response['weight']/(response['height'] * response['height']),2)
table_1.append([name, height, weight, bmi])
for field in response['types']:
table_2.append([name, field['type']['name']])
pokemonBasicData = pd.DataFrame(table_1, columns =['Name', 'Height', 'Weight', 'BMI'])
pokemonBasicData.sort_values('BMI',ascending=False ,inplace=True)
pokemonType = pd.DataFrame(table_2, columns =['Name', 'Type'])
pokemonBasicData.to_csv('pokemonBasicData')
pokemonType.to_csv('pokemonType')