|
import streamlit as st |
|
import pandas as pd |
|
import plotly.express as px |
|
from ydata_profiling import ProfileReport |
|
from statsmodels.stats.outliers_influence import variance_inflation_factor |
|
|
|
|
|
st.set_page_config( |
|
page_title="Enhanced Data Profiling", |
|
layout="wide", |
|
page_icon="📊" |
|
) |
|
|
|
|
|
custom_css = """ |
|
<style> |
|
/* Make the entire background white */ |
|
body { |
|
background-color: #ffffff !important; |
|
font-family: 'Roboto', sans-serif; |
|
} |
|
|
|
/* Headers and titles */ |
|
h1, h2, h3, h4 { |
|
color: #2c3e50; |
|
font-weight: 700; |
|
} |
|
|
|
/* The main Streamlit container */ |
|
[data-testid="stAppViewContainer"] { |
|
background-color: #ffffff !important; |
|
} |
|
|
|
/* Individual content containers */ |
|
.css-1d391kg, .css-hxt7ib { |
|
background-color: #ffffff !important; |
|
border-radius: 15px; |
|
padding: 30px; |
|
margin-bottom: 20px; |
|
box-shadow: 0 8px 16px rgba(0,0,0,0.1); |
|
} |
|
|
|
/* Sidebar styling */ |
|
[data-testid="stSidebar"] { |
|
background-color: #34495e !important; |
|
color: #ecf0f1 !important; |
|
font-size: 16px; |
|
} |
|
[data-testid="stSidebar"] .css-1d391kg { |
|
background-color: #2c3e50 !important; |
|
border-radius: 10px; |
|
} |
|
</style> |
|
""" |
|
st.markdown(custom_css, unsafe_allow_html=True) |
|
|
|
|
|
st.title("Enhanced Data Profiling") |
|
st.markdown("<h4 style='text-align: center; color: #2c3e50;'>Upload your CSV and explore it thoroughly!</h4>", unsafe_allow_html=True) |
|
|
|
|
|
st.sidebar.header("Upload & Options") |
|
uploaded_file = st.sidebar.file_uploader("Upload a CSV file", type="csv") |
|
|
|
|
|
df = None |
|
|
|
if uploaded_file is not None: |
|
|
|
df = pd.read_csv(uploaded_file) |
|
st.success("File uploaded successfully!") |
|
|
|
|
|
st.subheader("Dataset Quick Summary") |
|
col1, col2, col3, col4 = st.columns(4) |
|
col1.metric("Rows", f"{df.shape[0]}") |
|
col2.metric("Columns", f"{df.shape[1]}") |
|
missing_percentage = (df.isnull().sum().sum() / df.size) * 100 |
|
col3.metric("Missing %", f"{missing_percentage:.2f}%") |
|
duplicates = df.duplicated().sum() |
|
col4.metric("Duplicates", f"{duplicates}") |
|
|
|
st.write("---") |
|
|
|
|
|
if st.checkbox("Drop columns with > 50% missing data?"): |
|
threshold = df.shape[0] * 0.5 |
|
before_cols = df.shape[1] |
|
df = df.loc[:, df.isnull().sum() < threshold] |
|
after_cols = df.shape[1] |
|
st.success(f"Dropped {before_cols - after_cols} columns. Remaining columns: {after_cols}") |
|
|
|
|
|
numeric_cols = df.select_dtypes(include="number").columns.tolist() |
|
if numeric_cols: |
|
st.subheader("Optional Quick Histogram") |
|
selected_col = st.selectbox("Select a numeric column", numeric_cols) |
|
if selected_col: |
|
fig_hist = px.histogram(df, x=selected_col, nbins=50, title=f"Histogram of {selected_col}") |
|
fig_hist.update_traces(opacity=0.8) |
|
st.plotly_chart(fig_hist, use_container_width=True) |
|
|
|
|
|
st.subheader("Comprehensive Profiling Report") |
|
with st.spinner("Generating profiling report..."): |
|
profile = ProfileReport(df, title="Profiling Report", explorative=True) |
|
report_html = profile.to_html() |
|
|
|
|
|
st.components.v1.html(report_html, height=1200, scrolling=True) |
|
|
|
|
|
st.write("### Download the Profiling Report") |
|
st.download_button( |
|
label="Download HTML", |
|
data=report_html.encode('utf-8'), |
|
file_name="profiling_report.html", |
|
mime="text/html" |
|
) |
|
else: |
|
st.info("Awaiting CSV file upload.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|