简体   繁体   中英

Perform apply function in multiple column using pandas

I am trying to find rows where none of the three actors' Facebook likes should be less than half of the other two. 在此处输入图像描述

But i am getting an error KeyError: 'actor_1_facebook_likes' .Could you please help me with this.

I wanted to show you a much cleaner and performant way that you can write the code. Create the conditions and use ~ to drop the rows that meet those conditions. I hope this helps:

a1 = popular_trio['actor_1_facebook_likes']
a2 = popular_trio['actor_2_facebook_likes']
a3 = popular_trio['actor_3_facebook_likes']

c1 = (a1/2) < a2
c2 = (a2/2) < a1
c3 = (a3/2) < a2
c4 = (a1/2) < a3
c5 = (a2/2) < a3
c6 = (a3/2) < a1

popular_trio[~(c1|c2|c3|c4|c5|c6)] # or try popular_trio[~((c1)|(c2)|(c3)|(c4)|(c5)|(c6))]

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