I have dictionaries named Bgf
, Arf
and so on which have multiple dataframes
in them.
I am now creating a function that takes the name of the dictionary as a parameter by the user and then isolates dataframes
whose names end with '_with_lof' in that dataframe. Now the dfs
that are isolated must be stored in a new empty dict and the dict must have a name format as follows: 'dictionary'_filtered.
For example:
the dictionary Bgf
has the following dfs
:
s24_df
s25_df
s26_df
s27_df
dataframes
merged_df
s7_with_lof
s1_with_lof
Now, I want to isolate the dfs
whose name contain the string _with_lof
. Here s7_with_lof & s1_with_lof match. Now these two dfs
must be stored a new dictionary whose name must be Bgf_filtered
.
Similary, if the user gives Arf
as the parameter, then the new dictionary name must be Arf_filtered
.
My code:
def filtered(dictionary):
filter_string = '_with_lof'
**dictionary**_filtered = {k: v for (k, v) in Bgf.items() if filter_string in k}
Now, when the user does:
filtered('Bgf')
the Bgf
must be used in the third line of the function for creating the new dict as Bgf_filtered
.
Is there a way this can be done?