awacke1's picture
Update app.py
6047d40
raw
history blame
1.8 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")
for index, row in data.iterrows():
fig.add_trace(go.Scattergeo(
lon=[row['Longitude']],
lat=[row['Latitude']],
text=f"{row['Corporation']} - ${row['Revenue']}B",
mode='text',
))
fig.update_layout(title="Top Corporations by State in the United States")
return fig
# Function to generate the CSV file
def generate_csv(data):
top_corporations = data.nlargest(2, 'Revenue')
csv_file = top_corporations.to_csv(index=False)
return csv_file
st.title('Top Corporations 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 ๐Ÿ—บ๏ธ')
# Download CSV button
download_csv_button = st.button('Download Top Two Corporations CSV ๐Ÿ“ฅ')
if display_map_button or download_csv_button:
if uploaded_files:
for uploaded_file in uploaded_files:
data = pd.read_csv(uploaded_file)
if display_map_button:
st.write(f"Map for {uploaded_file.name}")
st.plotly_chart(plot_map(data))
if download_csv_button:
csv_file = generate_csv(data)
st.download_button(
label="Download CSV File",
data=csv_file,
file_name="top_two_corporations.csv",
mime="text/csv"
)
else:
st.write("Please upload a CSV file to proceed.")