Skip to content

Instantly share code, notes, and snippets.

@andrewgilmartin
Created December 27, 2025 17:22
Show Gist options
  • Select an option

  • Save andrewgilmartin/65047877cc9fbb611d7f394f54cd5215 to your computer and use it in GitHub Desktop.

Select an option

Save andrewgilmartin/65047877cc9fbb611d7f394f54cd5215 to your computer and use it in GitHub Desktop.
import streamlit as st
import pandas as pd
def main():
st.title("Cities Explorer!")
cities = load_cities()
populations = cities.groupby('state_id', as_index=False)['population'].sum()
st.bar_chart(populations, x='state_id', y='population')
states = cities['state_id'].unique()
states.sort()
state_selected = st.selectbox("Pick a state", states, )
state_cities = cities[ cities['state_id'] == state_selected ].sort_values('city_ascii')
state_population = state_cities['population'].sum()
state_cities['population_scale'] = state_cities['population'] / state_population * 10000 + 1000
st.bar_chart(state_cities, x='city_ascii', x_label='City', y='population', y_label='Population')
st.map(state_cities, latitude='lat', longitude='lng', size='population_scale')
@st.cache_data
def load_cities():
cities = pd.read_csv("./uscities.csv")
return cities
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment