File size: 1,430 Bytes
e5d4c51
11ca03b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5d4c51
11ca03b
 
 
 
 
 
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
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.")