Can you show me fish landing in the Northeast US over the past 20 years
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
st.title("Northeast US Fish Landings")
# Load data from NOAA Fisheries
# 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_data():
url = "https://corsproxy.io/?https://foss.nmfs.noaa.gov/apexfoss/f?p=215:200:::::P200_SPECIES_ID:&cs=3PScjfNoS4dlX9T4nWAM74G_V92MGp_4o5I5uEQdXj-FhRkgIphYzRrC5-RVs0AkV2sWOt1UfQPZhlslLNu_Fgg"
df = pd.read_csv(url)
# Clean and process data
df['YEAR'] = pd.to_numeric(df['YEAR'], errors='coerce')
df['POUNDS'] = pd.to_numeric(df['POUNDS'].str.replace(',', ''), errors='coerce')
df['VALUE'] = pd.to_numeric(df['VALUE'].str.replace(',', ''), errors='coerce')
# Filter last 20 years and Northeast region
current_year = pd.Timestamp.now().year
df = df[df['YEAR'] >= current_year - 20]
northeast_states = ['MAINE', 'NEW HAMPSHIRE', 'MASSACHUSETTS', 'RHODE ISLAND',
'CONNECTICUT', 'NEW YORK', 'NEW JERSEY']
df = df[df['STATE'].isin(northeast_states)]
return df
# Load the data
try:
df = load_data()
# Create yearly summary
yearly_summary = df.groupby('YEAR').agg({
'POUNDS': 'sum',
'VALUE': 'sum'
}).reset_index()
# Create plots
fig_pounds = px.line(yearly_summary, x='YEAR', y='POUNDS',
title='Total Fish Landings in Northeast US (Pounds)',
labels={'POUNDS': 'Pounds', 'YEAR': 'Year'})
st.plotly_chart(fig_pounds)
fig_value = px.line(yearly_summary, x='YEAR', y='VALUE',
title='Value of Fish Landings in Northeast US (USD)',
labels={'VALUE': 'Value (USD)', 'YEAR': 'Year'})
st.plotly_chart(fig_value)
# Show data table
st.subheader("Yearly Summary Data")
st.dataframe(yearly_summary.style.format({
'POUNDS': '{:,.0f}',
'VALUE': '${:,.2f}'
}))
except Exception as e:
st.error("""
Unable to load the data. This might be due to:
1. Connection issues with the NOAA Fisheries database
2. Changes in the data format or URL
3. CORS proxy limitations
Please try again later or check if the data source is available.
""")
st.exception(e)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?