import pandas as pd
import streamlit as st
import plotly.express as px
# Classy and centered title
st.markdown(
"""
Tips Dataset Dashboard
""",
unsafe_allow_html=True
)
# File Upload
file = st.file_uploader("📁 Upload a CSV file", type=["csv"])
if file is not None:
df = pd.read_csv(file)
st.markdown("### 🔍 Preview of Data")
st.write(df.head())
# Separate Numerical and Categorical Columns
num = df.select_dtypes('number')
cat = df.select_dtypes('object')
numerical = num.columns.tolist()
categorical = cat.columns.tolist()
st.markdown("### 🟨 Categorical Features")
st.write(cat)
st.markdown("### 🟦 Numerical Features")
st.write(num)
# 📊 Categorical Feature Analysis
st.markdown("## 📋 Categorical Feature Analysis")
for col in categorical:
st.write(f"### 🔸 Feature: `{col}`")
st.write("🔢 Value Counts:")
st.write(df[col].value_counts())
st.write("📜 Unique Values:")
st.write(df[col].unique())
st.write("🧮 Number of Unique Values:", df[col].nunique())
st.write("❓ Missing Values:", df[col].isnull().sum())
st.markdown("---")
# 📈 Numerical Feature Analysis
st.markdown("## 📊 Numerical Feature Analysis")
for col in numerical:
st.write(f"### 🔹 Feature: `{col}`")
st.write("📏 Mean:", df[col].mean())
st.write("🪙 Median:", df[col].median())
st.write("📉 Std Deviation:", df[col].std())
st.write("📐 Variance:", df[col].var())
st.write("📈 Skewness:", df[col].skew())
st.write("🔺 Kurtosis:", df[col].kurt())
st.write("🔽 Minimum:", df[col].min())
st.write("🔼 Maximum:", df[col].max())
st.write("❓ Missing Values:", df[col].isnull().sum())
st.markdown("---")
# 🔗 Bivariate Analysis
st.markdown("## 🔗 Bivariate Analysis")
# Scatter Plot
st.markdown("### 📍 Scatter Plot")
num_x = st.selectbox('🧭 Select X-axis (Numerical)', numerical, key='scatter_x')
num_y = st.selectbox('📌 Select Y-axis (Numerical)', numerical, key='scatter_y')
if num_x and num_y:
st.write(f"🔎 Scatter plot between `{num_x}` and `{num_y}`")
fig = px.scatter(df, x=num_x, y=num_y, title=f'Scatter plot: {num_x} vs {num_y}')
st.plotly_chart(fig)
# Box Plot
st.markdown("### 🎁 Box Plot")
cat_feature = st.selectbox('🧊 Select Category', categorical, key='box_cat')
num_feature = st.selectbox('📐 Select Value (Numerical)', numerical, key='box_num')
if cat_feature and num_feature:
fig = px.box(df, x=cat_feature, y=num_feature, title=f'Box plot of {num_feature} by {cat_feature}')
st.plotly_chart(fig)
# Correlation Matrix
st.markdown("### 🔥 Correlation Matrix")
corr = num.corr()
fig = px.imshow(corr, text_auto=True, title='Correlation Heatmap')
st.plotly_chart(fig)
# Pairplot
st.markdown("### 🌐 Pairplot")
if len(numerical) > 1:
fig = px.scatter_matrix(df, dimensions=numerical, title='Pairplot of Numerical Features')
st.plotly_chart(fig)
# Count Plot
st.markdown("### 📊 Count Plot")
cat_feature_count = st.selectbox('📋 Select a categorical feature', categorical, key='count_plot')
if cat_feature_count:
value_counts_df = df[cat_feature_count].value_counts().reset_index()
value_counts_df.columns = [cat_feature_count, 'Count']
fig = px.bar(value_counts_df, x=cat_feature_count, y='Count',
title=f'Count Plot for {cat_feature_count}',
labels={cat_feature_count: cat_feature_count, 'Count': 'Count'})
st.plotly_chart(fig)
# Distribution Plot
st.markdown("### 🧮 Distribution Plot")
num_feature_dist = st.selectbox('🔢 Select a numerical feature', numerical, key='dist_plot')
if num_feature_dist:
fig = px.histogram(df, x=num_feature_dist, nbins=30,
title=f'Distribution of {num_feature_dist}')
st.plotly_chart(fig)
# Pie Chart
st.markdown("### 🥧 Pie Chart")
cat_feature_pie = st.selectbox('🧠 Select categorical feature for pie chart', categorical, key='pie_chart')
if cat_feature_pie:
fig = px.pie(df, names=cat_feature_pie, title=f'Pie Chart of {cat_feature_pie}')
st.plotly_chart(fig)
else:
st.warning("📁 Please upload a CSV file to begin.")