Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
from pandas_profiling import ProfileReport | |
import base64 | |
st.set_page_config(page_title="Data Browser", page_icon=":bar_chart:") | |
st.title("Data Browser") | |
# File upload | |
st.header("Upload your data file") | |
uploaded_file = st.file_uploader("", type=["csv", "xlsx"]) | |
if uploaded_file is not None: | |
# Determine file type | |
file_ext = uploaded_file.name.split(".")[-1] | |
if file_ext == "csv": | |
df = pd.read_csv(uploaded_file) | |
elif file_ext in ["xls", "xlsx"]: | |
df = pd.read_excel(uploaded_file) | |
# Display basic info | |
st.write(f"Number of rows: {df.shape[0]}") | |
st.write(f"Number of columns: {df.shape[1]}") | |
st.write("Sample data:") | |
st.dataframe(df.head()) | |
# Generate pandas profiling report | |
report = ProfileReport(df, explorative=True) | |
st.header("Data profiling") | |
st.write("Data distribution:") | |
st_profile_report(report) | |
# Download link for example data | |
example_csv = """name,age,income | |
Alice,25,50000 | |
Bob,30,70000 | |
Charlie,35,90000""" | |
csv_filename = "example.csv" | |
b64 = base64.b64encode(example_csv.encode()).decode() | |
href = f'<a href="data:file/csv;base64,{b64}" download="{csv_filename}">Download example data</a>' | |
st.markdown(href, unsafe_allow_html=True) | |