BilalCode's picture
Create app.py
074873a verified
Raw
History Blame Contribute Delete
1.85 kB
import streamlit as st
import pandas as pd
import plotly.express as px
st.set_page_config(page_title="CSV Viewer Dashboard", layout="wide")
st.title("πŸ“Š Data Dashboard - CSV Viewer")
st.write("Upload your CSV file to view data and explore insights.")
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
if uploaded_file is not None:
try:
df = pd.read_csv(uploaded_file)
st.subheader("🧾 Data Preview")
st.dataframe(df, use_container_width=True)
st.subheader("πŸ“ˆ Quick Stats")
st.write(df.describe(include='all'))
st.subheader("πŸ“Š Column Types")
st.write(df.dtypes)
st.subheader("πŸ“Œ Plot Data")
chart_type = st.selectbox("Choose chart type", ["Bar Chart", "Line Chart", "Pie Chart"])
column_options = df.select_dtypes(include=["object", "category", "int", "float"]).columns.tolist()
if chart_type == "Pie Chart":
col1 = st.selectbox("Category Column", column_options)
col2 = st.selectbox("Value Column", df.select_dtypes(include=["int", "float"]).columns)
fig = px.pie(df, names=col1, values=col2, title=f'{col1} vs {col2}')
st.plotly_chart(fig, use_container_width=True)
else:
x_col = st.selectbox("X-axis", column_options)
y_col = st.selectbox("Y-axis", df.select_dtypes(include=["int", "float"]).columns)
if chart_type == "Bar Chart":
fig = px.bar(df, x=x_col, y=y_col, title=f'{x_col} vs {y_col}')
elif chart_type == "Line Chart":
fig = px.line(df, x=x_col, y=y_col, title=f'{x_col} vs {y_col}')
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
st.error(f"❌ Error: {e}")
else:
st.info("πŸ“€ Please upload a CSV file to get started.")