Spaces:
Sleeping
Sleeping
| 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.") | |