0

I am trying to find rows where none of the three actors' Facebook likes should be less than half of the other two. enter image description here

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

2

1 Answer 1

1

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))]
Sign up to request clarification or add additional context in comments.

1 Comment

@jezrael yes, I know. I just couldn't help myself to clean up the code ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.