简体   繁体   中英

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

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?

genre_list = ["Horror", "Thriller"]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM