File size: 1,169 Bytes
292b840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd

# Sample DataFrame for demonstration
data = {
    'product_code': [1, 2, 3, 4, 5],
    'label': ['Label1', 'Label2', 'Label3', 'Label4', 'Label1'],
    'amount': [250, 450, 300, 200, 500]
}
df = pd.DataFrame(data)

# Streamlit App
st.title('DataFrame Column Selector')

# Display the original DataFrame
st.subheader('Original DataFrame')
st.write(df)

# Column selection for inclusion
st.subheader('Select Columns to Include')
include_columns = st.multiselect('Select columns to include', options=df.columns, default=df.columns.tolist())

# Column selection for exclusion
st.subheader('Select Columns to Exclude')
exclude_columns = st.multiselect('Select columns to exclude', options=df.columns, default=[])

# Filter DataFrame to include only selected columns
if include_columns:
    filtered_df = df[include_columns]
else:
    filtered_df = df

# Further filter DataFrame to exclude specified rows
if exclude_columns:
    filtered_df = filtered_df[~filtered_df[exclude_columns].apply(lambda x: x.isin(include_columns)).any(axis=1)]

# Display the filtered DataFrame
st.subheader('Filtered DataFrame')
st.write(filtered_df)