ExcelApp / app.py
rashid200gb's picture
Create app.py
03474ee verified
Raw History Blame Contribute Delete
1.34 kB
import streamlit as st
import pandas as pd
st.title("πŸ“Š Profit & Loss Dashboard from Excel")
# Upload Excel file
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"])
if uploaded_file:
# Load Excel data
df = pd.read_excel(uploaded_file)
st.subheader("πŸ” Raw Data Preview")
st.write(df.head())
# Show duplicates
duplicate_rows = df[df.duplicated()]
if not duplicate_rows.empty:
st.warning("⚠️ Duplicate rows found:")
st.dataframe(duplicate_rows)
else:
st.success("βœ… No duplicate rows found.")
# Option to drop duplicates
if st.button("Remove Duplicates"):
df = df.drop_duplicates()
st.success("Duplicates removed.")
st.dataframe(df)
# Select columns for Pivot Table
st.subheader("πŸ“Œ Create Pivot Table for P&L")
pivot_col = st.selectbox("Select column for grouping (e.g., Item Name)", df.columns)
value_col = st.selectbox("Select value column (e.g., Profit/Loss/Revenue)", df.columns)
# Generate Pivot Table
pivot_table = df.pivot_table(index=pivot_col, values=value_col, aggfunc='sum')
st.subheader("πŸ“ˆ Pivot Table Result")
st.dataframe(pivot_table)
st.download_button("Download Pivot Table as CSV", pivot_table.to_csv().encode('utf-8'), file_name="pnl_pivot.csv")