-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobtener_datos.py
More file actions
26 lines (22 loc) · 827 Bytes
/
Copy pathobtener_datos.py
File metadata and controls
26 lines (22 loc) · 827 Bytes
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
import requests
import pandas as pd
# Obtener datos de la PokeAPI
response = requests.get("https://pokeapi.co/api/v2/pokemon?limit=100")
data = response.json()['results']
# Preprocesamiento de datos
pokemon_attributes = []
for pokemon in data:
pokemon_data = requests.get(pokemon['url']).json()
attributes = {
'nombre': pokemon['name'],
'tipo': pokemon_data['types'][0]['type']['name'],
'experiencia_base': pokemon_data['base_experience'],
'altura': pokemon_data['height'],
'peso': pokemon_data['weight']
}
pokemon_attributes.append(attributes)
# Crear DataFrame
df = pd.DataFrame(pokemon_attributes, columns=[
'nombre', 'tipo', 'experiencia_base', 'altura', 'peso'])
# Guardar los datos en un archivo CSV
df.to_csv('pokemon_data.csv', index=False)