Spaces:
Sleeping
Sleeping
File size: 4,675 Bytes
2a6b09f | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import pandas as pd
import streamlit as st
import plotly.express as px
# Classy and centered title
st.markdown(
"""
<h1 style="text-align: center; color: skyblue;"> Tips Dataset Dashboard</h1>
""",
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.") |