Home > OS >  How to return only rows with required column values from pandas dataframe
How to return only rows with required column values from pandas dataframe

Time:03-08

Image of movie genres with 1-5 scale

I have a dataset which contains different movie genres as column names and their values(1 to 5) in their respective columns. Now, what I want is, to return rows which contain only values 3 to 5 and discard others. So far I have used the code

req_horr = req_data [(req_data['Horror'] >= 3)]

Where req_data is dataframe in image.

With the above code I can only return rows with desired values in 1 column(in this case column 'Horror'). But I need a return of dataframe with desired values in every columns. What is the code for that?

CodePudding user response:

genre_list = ["Horror", "Thriller"]

req_data.loc[(req_data[genre_list] >= 3).all(axis=1)]

  • Related