I have a problem , I have one pandas Of dataframe:
book_ratings
I want to base it on User 1 To User 4 The score , Find out if the score reaches 5 The name of the book divided
I tried to use book_ratings.isin([5]), We can only find True and False Value , How to return the corresponding value ToT
You can do this :
import pandas as pdpd.set_option('display.max_columns',None)df=pd.DataFrame({'title':['a','b','c','d'],'author':['aa','bb','cc','dd'],'user1':[3.2,2.9,2.5,2.9],'user2':[5.0,1.3,4.0,3.8],'user3':[2.0,2.3,2.8,4.0],'user4':[4.0,3.5,4.0,5.0]})a=df.iloc[:,2:].isin([5]).any(axis=1)df=df.mask(~a).dropna()print(df)
result:
title author user1 user2 user3 user40 a aa 3.2 5.0 2.0 4.03 d dd 2.9 3.8 4.0 5.0