Spaces:
Sleeping
Sleeping
File size: 1,777 Bytes
9891086 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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.")
|