an app that allows me to plot pokemon data
To upload files, please first save the app
import streamlit as st
import pandas as pd
import requests
st.title("Pokemon Data Plotter")
# NOTE: Using corsproxy.io because we're in a WASM environment. If running locally,
# you can remove the corsproxy.io prefix.
@st.cache_data
def load_pokemon_data():
url = "https://corsproxy.io/?https://raw.githubusercontent.com/fanzeyi/pokemon.json/master/pokedex.json"
response = requests.get(url)
data = response.json()
# Convert to DataFrame
df = pd.DataFrame(data)
# Explode the stats list into separate columns
stats_df = pd.DataFrame([{stat['name']: stat['base_stat'] for stat in pokemon['stats']}
for pokemon in data])
# Combine basic info with stats
df = pd.DataFrame({
'name': [p['name']['english'] for p in data],
'type': [p['type'][0] for p in data], # Using first type only
'HP': stats_df['HP'],
'Attack': stats_df['Attack'],
'Defense': stats_df['Defense'],
'Sp. Attack': stats_df['Sp. Attack'],
'Sp. Defense': stats_df['Sp. Defense'],
'Speed': stats_df['Speed']
})
return df
# Load data
df = load_pokemon_data()
# Sidebar controls
st.sidebar.header("Plot Controls")
# Select attributes to plot
x_axis = st.sidebar.selectbox(
"Choose X-axis",
['HP', 'Attack', 'Defense', 'Sp. Attack', 'Sp. Defense', 'Speed']
)
y_axis = st.sidebar.selectbox(
"Choose Y-axis",
['HP', 'Attack', 'Defense', 'Sp. Attack', 'Sp. Defense', 'Speed'],
index=1
)
# Create scatter plot
st.subheader(f"{x_axis} vs {y_axis} for Pokemon")
st.scatter_chart(
data=df,
x=x_axis,
y=y_axis,
color='type',
size=None,
use_container_width=True
)
# Display raw data
if st.checkbox("Show raw data"):
st.write(df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?