Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| st.set_page_config(page_title="Data Visualization App", page_icon="π", layout="wide") | |
| st.title("π Interactive Data Visualization App") | |
| uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"]) | |
| if uploaded_file is not None: | |
| df = pd.read_csv(uploaded_file) | |
| st.subheader("π Data Preview") | |
| st.dataframe(df.head()) | |
| st.subheader("π Data Summary") | |
| st.write(df.describe()) | |
| st.subheader("π¨ Visualization Options") | |
| columns = df.columns.tolist() | |
| chart_type = st.selectbox("Select chart type", ["Line", "Bar", "Scatter", "Histogram", "Pie"]) | |
| x_axis = st.selectbox("Select X-axis", columns) | |
| y_axis = st.selectbox("Select Y-axis", columns) | |
| fig, ax = plt.subplots(figsize=(8, 5)) | |
| if chart_type == "Line": | |
| ax.plot(df[x_axis], df[y_axis]) | |
| elif chart_type == "Bar": | |
| ax.bar(df[x_axis], df[y_axis]) | |
| elif chart_type == "Scatter": | |
| ax.scatter(df[x_axis], df[y_axis]) | |
| elif chart_type == "Histogram": | |
| ax.hist(df[y_axis], bins=20) | |
| elif chart_type == "Pie": | |
| df.groupby(x_axis)[y_axis].sum().plot(kind="pie", autopct="%1.1f%%", ax=ax) | |
| ax.set_xlabel(x_axis) | |
| ax.set_ylabel(y_axis) | |
| ax.set_title(f"{chart_type} Chart of {y_axis} vs {x_axis}") | |
| st.pyplot(fig) | |
| else: | |
| st.info("π Upload a CSV file to begin exploring your data.") | |