Home > database >  how to apply same filter to multiple dataframes
how to apply same filter to multiple dataframes

Time:09-15

How can I filter the list of dataframes with the same column category in one code?

filter_list = [df1, df2, df3, df4]

for name in filter_list:
     name.columns[columns['category'] == 'category1']

CodePudding user response:

You need to use a method that has an inplace argument for the assignment in a for loop.

I will demonstrate with dropping everything where category does not equal category1

filter_list = [df1,df2,df3,df4]

for x in filter_list:
    x.drop(x[x['category']!='category1'].index, inplace=True)
  • Related