how to apply same filter to multiple dataframes

Question:

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']
Asked By: Josh

||

Answers:

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)
Answered By: saliustripe
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.