I have observed that my code functions correctly and filters data according to user selection. However, I would like to attempt transferring the user-selected or filtered data to a new pandas DataFrame. Unfortunately, the data is not being transferred to the new DataFrame, nor is the selected filtered data being converted into a list for use in the new pandas DataFrame. I would appreciate any ideas and the correct code to achieve this.
my code
import streamlit as st
import numpy as np
import pandas as pd
from streamlit_dynamic_filters import DynamicFilters
data = {
‘region’: [‘North America’, ‘North America’, ‘Europe’, ‘Oceania’,
‘North America’, ‘North America’, ‘Europe’, ‘Oceania’,
‘North America’, ‘North America’, ‘Europe’, ‘Oceania’],
‘country’: [‘USA’, ‘Canada’, ‘UK’, ‘Australia’,
‘USA’, ‘Canada’, ‘UK’, ‘Australia’,
‘USA’, ‘Canada’, ‘UK’, ‘Australia’],
‘city’: [‘New York’, ‘Toronto’, ‘London’, ‘Sydney’,
‘New York’, ‘Toronto’, ‘London’, ‘Sydney’,
‘New York’, ‘Toronto’, ‘London’, ‘Sydney’],
‘district’: [‘Manhattan’, ‘Downtown’, ‘Westminster’, ‘CBD’,
‘Brooklyn’, ‘Midtown’, ‘Kensington’, ‘Circular Quay’,
‘Queens’, ‘Uptown’, ‘Camden’, ‘Bondi’]
}
df = pd.DataFrame(data)
dynamic_filters = DynamicFilters(df, filters=[‘region’, ‘country’, ‘city’, ‘district’])
st.write(“Apply filters in any order
”)
dynamic_filters.display_filters(location=‘columns’, num_columns=2, gap=‘large’)
dynamic_filters.display_df()
st.write(‘Testing for treanser data to new datafreame’)
if st.button(‘Check availability’):
df2 = pd.DataFrame(dynamic_filters.display_df())
st.write(df2) # did not show the filter jor selected data show blanck dataframe