Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Data Visualization App", page_icon="π", layout="wide")
|
| 6 |
+
|
| 7 |
+
st.title("π Interactive Data Visualization App")
|
| 8 |
+
|
| 9 |
+
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 10 |
+
|
| 11 |
+
if uploaded_file is not None:
|
| 12 |
+
df = pd.read_csv(uploaded_file)
|
| 13 |
+
st.subheader("π Data Preview")
|
| 14 |
+
st.dataframe(df.head())
|
| 15 |
+
|
| 16 |
+
st.subheader("π Data Summary")
|
| 17 |
+
st.write(df.describe())
|
| 18 |
+
|
| 19 |
+
st.subheader("π¨ Visualization Options")
|
| 20 |
+
columns = df.columns.tolist()
|
| 21 |
+
|
| 22 |
+
chart_type = st.selectbox("Select chart type", ["Line", "Bar", "Scatter", "Histogram", "Pie"])
|
| 23 |
+
x_axis = st.selectbox("Select X-axis", columns)
|
| 24 |
+
y_axis = st.selectbox("Select Y-axis", columns)
|
| 25 |
+
|
| 26 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
| 27 |
+
|
| 28 |
+
if chart_type == "Line":
|
| 29 |
+
ax.plot(df[x_axis], df[y_axis])
|
| 30 |
+
elif chart_type == "Bar":
|
| 31 |
+
ax.bar(df[x_axis], df[y_axis])
|
| 32 |
+
elif chart_type == "Scatter":
|
| 33 |
+
ax.scatter(df[x_axis], df[y_axis])
|
| 34 |
+
elif chart_type == "Histogram":
|
| 35 |
+
ax.hist(df[y_axis], bins=20)
|
| 36 |
+
elif chart_type == "Pie":
|
| 37 |
+
df.groupby(x_axis)[y_axis].sum().plot(kind="pie", autopct="%1.1f%%", ax=ax)
|
| 38 |
+
|
| 39 |
+
ax.set_xlabel(x_axis)
|
| 40 |
+
ax.set_ylabel(y_axis)
|
| 41 |
+
ax.set_title(f"{chart_type} Chart of {y_axis} vs {x_axis}")
|
| 42 |
+
st.pyplot(fig)
|
| 43 |
+
else:
|
| 44 |
+
st.info("π Upload a CSV file to begin exploring your data.")
|