Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
from pandas_profiling import ProfileReport
|
5 |
+
import base64
|
6 |
+
|
7 |
+
st.set_page_config(page_title="Data Browser", page_icon=":bar_chart:")
|
8 |
+
|
9 |
+
st.title("Data Browser")
|
10 |
+
|
11 |
+
# File upload
|
12 |
+
st.header("Upload your data file")
|
13 |
+
uploaded_file = st.file_uploader("", type=["csv", "xlsx"])
|
14 |
+
|
15 |
+
if uploaded_file is not None:
|
16 |
+
# Determine file type
|
17 |
+
file_ext = uploaded_file.name.split(".")[-1]
|
18 |
+
if file_ext == "csv":
|
19 |
+
df = pd.read_csv(uploaded_file)
|
20 |
+
elif file_ext in ["xls", "xlsx"]:
|
21 |
+
df = pd.read_excel(uploaded_file)
|
22 |
+
|
23 |
+
# Display basic info
|
24 |
+
st.write(f"Number of rows: {df.shape[0]}")
|
25 |
+
st.write(f"Number of columns: {df.shape[1]}")
|
26 |
+
st.write("Sample data:")
|
27 |
+
st.dataframe(df.head())
|
28 |
+
|
29 |
+
# Generate pandas profiling report
|
30 |
+
report = ProfileReport(df, explorative=True)
|
31 |
+
st.header("Data profiling")
|
32 |
+
st.write("Data distribution:")
|
33 |
+
st_profile_report(report)
|
34 |
+
|
35 |
+
# Download link for example data
|
36 |
+
example_csv = """name,age,income
|
37 |
+
Alice,25,50000
|
38 |
+
Bob,30,70000
|
39 |
+
Charlie,35,90000"""
|
40 |
+
csv_filename = "example.csv"
|
41 |
+
b64 = base64.b64encode(example_csv.encode()).decode()
|
42 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{csv_filename}">Download example data</a>'
|
43 |
+
st.markdown(href, unsafe_allow_html=True)
|