Spaces:
Sleeping
Sleeping
| 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.") |