Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
|
4 |
-
# Sample DataFrame for demonstration
|
5 |
-
data = {
|
6 |
-
'product_code': [1, 2, 3, 4, 5],
|
7 |
-
'label': ['Label1', 'Label2', 'Label3', 'Label4', 'Label1'],
|
8 |
-
'amount': [250, 450, 300, 200, 500]
|
9 |
-
}
|
10 |
-
df = pd.DataFrame(data)
|
11 |
-
|
12 |
# Streamlit App
|
13 |
-
st.title('
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
# Column selection for inclusion
|
20 |
-
st.subheader('Select Columns to Include')
|
21 |
-
include_columns = st.multiselect('Select columns to include', options=df.columns, default=df.columns.tolist())
|
22 |
|
23 |
-
# Filter DataFrame to include only selected columns
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
-
# Display the filtered DataFrame
|
27 |
-
st.subheader('Filtered DataFrame')
|
28 |
-
st.write(filtered_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Streamlit App
|
5 |
+
st.title('CSV Column Selector')
|
6 |
+
|
7 |
+
# File uploader for CSV files
|
8 |
+
uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
|
9 |
|
10 |
+
if uploaded_file is not None:
|
11 |
+
# Read the CSV file into a DataFrame
|
12 |
+
df = pd.read_csv(uploaded_file)
|
13 |
+
|
14 |
+
# Display the original DataFrame
|
15 |
+
st.subheader('Original DataFrame')
|
16 |
+
st.write(df)
|
17 |
|
18 |
+
# Column selection for inclusion
|
19 |
+
st.subheader('Select Columns to Include')
|
20 |
+
include_columns = st.multiselect('Select columns to include', options=df.columns, default=df.columns.tolist())
|
21 |
|
22 |
+
# Filter DataFrame to include only selected columns
|
23 |
+
if include_columns:
|
24 |
+
filtered_df = df[include_columns]
|
25 |
+
else:
|
26 |
+
filtered_df = df
|
27 |
|
28 |
+
# Display the filtered DataFrame
|
29 |
+
st.subheader('Filtered DataFrame')
|
30 |
+
st.write(filtered_df)
|
31 |
+
|
32 |
+
# Option to download the filtered DataFrame
|
33 |
+
st.download_button(
|
34 |
+
label="Download Filtered DataFrame",
|
35 |
+
data=filtered_df.to_csv(index=False),
|
36 |
+
file_name='filtered_data.csv',
|
37 |
+
mime='text/csv'
|
38 |
+
)
|