tips-analyzer / project_2.py
HarshaX's picture
Upload 4 files
2a6b09f verified
Raw
History Blame Contribute Delete
4.68 kB
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.")