File size: 1,265 Bytes
7316ecd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

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)