Areef6's picture
Create app.py
9891086 verified
Raw
History Blame Contribute Delete
1.78 kB
import streamlit as st
import pandas as pd
import plotly.express as px
# App title
st.title("πŸ“Š Data Dashboard - CSV Viewer")
st.write("Upload a CSV file to explore data with summary stats and visualizations.")
# File uploader
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
if uploaded_file:
# Load data
df = pd.read_csv(uploaded_file)
# Show raw data
st.subheader("πŸ“ Raw Data")
st.dataframe(df)
# Summary statistics
st.subheader("πŸ“ˆ Summary Statistics")
st.write(df.describe())
# Column selection
numeric_cols = df.select_dtypes(include='number').columns.tolist()
categorical_cols = df.select_dtypes(include='object').columns.tolist()
# Chart section
st.subheader("πŸ“Š Visualizations")
chart_type = st.selectbox("Choose a chart type", ["Histogram", "Bar Chart", "Scatter Plot"])
if chart_type == "Histogram":
col = st.selectbox("Select numeric column for histogram", numeric_cols)
fig = px.histogram(df, x=col, title=f"Histogram of {col}")
st.plotly_chart(fig)
elif chart_type == "Bar Chart":
col = st.selectbox("Select categorical column for bar chart", categorical_cols)
fig = px.bar(df[col].value_counts().reset_index(),
x='index', y=col,
labels={'index': col, col: 'Count'},
title=f"Bar Chart of {col}")
st.plotly_chart(fig)
elif chart_type == "Scatter Plot":
x_axis = st.selectbox("X-axis", numeric_cols, key='x')
y_axis = st.selectbox("Y-axis", numeric_cols, key='y')
fig = px.scatter(df, x=x_axis, y=y_axis, title=f"{y_axis} vs {x_axis}")
st.plotly_chart(fig)
else:
st.info("Please upload a CSV file to begin.")