File size: 1,853 Bytes
074873a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import plotly.express as px

st.set_page_config(page_title="CSV Viewer Dashboard", layout="wide")

st.title("πŸ“Š Data Dashboard - CSV Viewer")
st.write("Upload your CSV file to view data and explore insights.")

uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])

if uploaded_file is not None:
    try:
        df = pd.read_csv(uploaded_file)

        st.subheader("🧾 Data Preview")
        st.dataframe(df, use_container_width=True)

        st.subheader("πŸ“ˆ Quick Stats")
        st.write(df.describe(include='all'))

        st.subheader("πŸ“Š Column Types")
        st.write(df.dtypes)

        st.subheader("πŸ“Œ Plot Data")
        chart_type = st.selectbox("Choose chart type", ["Bar Chart", "Line Chart", "Pie Chart"])
        column_options = df.select_dtypes(include=["object", "category", "int", "float"]).columns.tolist()

        if chart_type == "Pie Chart":
            col1 = st.selectbox("Category Column", column_options)
            col2 = st.selectbox("Value Column", df.select_dtypes(include=["int", "float"]).columns)
            fig = px.pie(df, names=col1, values=col2, title=f'{col1} vs {col2}')
            st.plotly_chart(fig, use_container_width=True)

        else:
            x_col = st.selectbox("X-axis", column_options)
            y_col = st.selectbox("Y-axis", df.select_dtypes(include=["int", "float"]).columns)
            if chart_type == "Bar Chart":
                fig = px.bar(df, x=x_col, y=y_col, title=f'{x_col} vs {y_col}')
            elif chart_type == "Line Chart":
                fig = px.line(df, x=x_col, y=y_col, title=f'{x_col} vs {y_col}')
            st.plotly_chart(fig, use_container_width=True)

    except Exception as e:
        st.error(f"❌ Error: {e}")
else:
    st.info("πŸ“€ Please upload a CSV file to get started.")