%%writefile streamlit_app.py
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
st.set_page_config(page_title="AI Data Handling Dashboard", layout="wide")
st.title("📊 Intelligent Data Handling Dashboard")
np.random.seed(42)
df = pd.DataFrame({
"CustomerID": [f"CUST{i:03d}" for i in range(1, 101)],
"Age": np.random.randint(18, 65, 100),
"Salary": np.random.randint(30000, 120000, 100),
"Department": np.random.choice(["HR", "Finance", "IT", "Marketing"], 100),
"PurchaseAmount": np.round(np.random.uniform(50, 2000, 100), 2)
})
st.subheader("🔍 Dataset Overview")
st.write("Shape:", df.shape)
st.write("Columns:", df.columns.tolist())
st.write("Data Types:")
st.write(df.dtypes)
st.write("Missing Values:")
st.write(df.isnull().sum())
st.subheader("📊 Statistical Summary")
st.dataframe(df.describe().round(2))
st.subheader("⚡ Interactive Filters")
department_filter = st.multiselect("Select Department(s):", options=df["Department"].unique(), default=df["Department"].unique())
filtered_df = df[df["Department"].isin(department_filter)]
st.write(f"Filtered Data ({len(filtered_df)} rows)")
st.dataframe(filtered_df.head(10))
st.subheader("📈 Visualizations")
col1, col2 = st.columns(2)
with col1:
st.write("**Age Distribution**")
fig_age = px.histogram(filtered_df, x="Age", nbins=10, title="Age Distribution")
st.plotly_chart(fig_age, use_container_width=True)
with col2:
st.write("**Salary Distribution**")
fig_salary = px.histogram(filtered_df, x="Salary", nbins=10, title="Salary Distribution")
st.plotly_chart(fig_salary, use_container_width=True)
st.write("**Purchase Amount vs Age**")
fig_scatter = px.scatter(filtered_df, x="Age", y="PurchaseAmount", color="Department", hover_data=["CustomerID"])
st.plotly_chart(fig_scatter, use_container_width=True)
df_count = filtered_df["Department"].value_counts().reset_index()
df_count.columns = ["Department", "Count"]
fig_count = px.bar(
df_count,
x="Department",
y="Count",
labels={"Department": "Department", "Count": "Number of Employees"},
title="Department Count"
)
st.plotly_chart(fig_count, use_container_width=True)
st.write("**Salary Boxplot by Department**")
fig_box = px.box(filtered_df, x="Department", y="Salary", color="Department")
st.plotly_chart(fig_box, use_container_width=True)