awacke1's picture
Update app.py
6f78413
raw
history blame
1.35 kB
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Function to plot the map
def plot_map(data):
fig = px.choropleth(locations=data['State'], locationmode="USA-states", scope="usa")
grouped_data = data.groupby('State')
for state, group in grouped_data:
top_corp = group.nlargest(1, 'Revenue')
text_label = f"{top_corp['Corporation'].iloc[0]} - ${top_corp['Revenue'].iloc[0]}B"
lon = group['Longitude'].mean()
lat = group['Latitude'].mean()
fig.add_trace(go.Scattergeo(
lon=[lon],
lat=[lat],
text=text_label,
mode='text',
))
fig.update_layout(title="Top Corporation by State in the United States")
return fig
st.title('Top Corporation by State in the United States 🏒')
# Upload CSV
uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True, type="csv")
# Display map button
display_map_button = st.button('Display Map of CSV Data πŸ—ΊοΈ')
if display_map_button:
if uploaded_files:
for uploaded_file in uploaded_files:
data = pd.read_csv(uploaded_file)
st.write(f"Map for {uploaded_file.name} 🌐")
st.plotly_chart(plot_map(data))
else:
st.write("Please upload a CSV file to proceed. πŸ“‘")