import streamlit as st import pandas as pd import plotly.express as px from datetime import datetime def load_data(): df = pd.read_csv('./global_superstore_2016.csv') df['Order Date'] = pd.to_datetime(df['Order Date']) df['Quarter'] = df['Order Date'].dt.to_period('Q') return df df = load_data() df_us = df[df['Country'] == 'United States'] df_us_pnl = df_us.groupby('Quarter')[['Sales', 'Profit', 'Shipping Cost', 'Discount']].sum().reset_index() df_us_pnl['Gross Profit'] = df_us_pnl['Sales'] - df_us_pnl['Discount'] df_us_pnl['Net Profit'] = df_us_pnl['Gross Profit'] - df_us_pnl['Shipping Cost'] df_us_pnl = df_us_pnl.sort_values(by='Quarter', ascending=False).head(6) st.title("P&L Table by Quarter for United States") st.write(df_us_pnl)