Hi,
I’ve made some progress with st.dataframe but am not sure how to add multiple lines to a line chart. I found instructions how to add additional columns but I need to select rows and ‘count’ (/‘size’) them for the additional lines in the chart, specifically, filtering on three variables in the ‘Fuel’ column (‘Electric’, ‘Hybrid Electric’, ‘Plug-in Hybrid Electric’), for each year.
I tried adding some code that @mathcatsand helped with here Issues connecting Streamlit features (st.multiselct) to real data (.csv) but after several days of trying many variations I could use some help. The code that as commented out below is one of the base version that Debbie helped out with but does not work in this situation.
Thanks,
Mike
import streamlit as st
import pandas as pd
st.write("Total Number of Models per Year for Electric, Hybrid and PHEV")
df = pd.read_csv(r'/home/mike/Environments/Streamlit/light-duty-vehicles-2023-12-25.csv')
df = df[['Manufacturer','Model', 'Model_Year', 'Fuel_Code', 'Fuel']]
df = df[df.Fuel.isin(['Electric','Hybrid Electric','Plug-in Hybrid Electric'])]
df = df.groupby(['Model_Year']).size().reset_index(name='Totals')
df = df.sort_values('Model_Year', ascending=False).reset_index(drop=True)
df = df.style.format(thousands='', precision=0)
st.dataframe(df, hide_index=True, use_container_width=True, height=400)
st.write(Line Chart)
#df = df['Fuel']
#propulsion_type = df.Fuel.unique()
#selected_types = st.multiselect("Fuel", propulsion_type)
#filtered_df = df[df["Fuel"].isin(selected_types)]
st.line_chart(df, x='Model_Year', y='Totals')
- running locally
- app is not deployed:
- app not on Github yet (locally only)
- Python 3.10.13, Streamlit 1.28.1