0

Currently i have a big list, of specific UserIds, that i want to select it is specific rows and formulate a df from the conjunction of the filters. I managed to achieve that. But the thing is they way i am currently doing is straight up ugly and lacks interactivity. And since the list of users is going to grow i wish to know a better way to formulate those users. Or just a cleaner way at least For those that are curious, no there is no other way of selecting those specific users.

The current code is as follows:

prod = (df['UserId'] == '225a33b9-2514-4686-a1e9-31279c66faee@tunnel.msging.net') | (df['UserId'] == 'c360515f-8d8a-44b7-9097-f968c3e06579@tunnel.msging.net') |(df['UserId'] == '63167be5-8a1e-44e6-bf32-3900e048b899@tunnel.msging.net') |(df['UserId'] == '225a33b9-2514-4686-a1e9-31279c66faee@tunnel.msging.net')
df[prod]
INGl0R1AM0R1
  • 1,532
  • 5
  • 16

1 Answers1

0

If you have a big list of user ids you want to check, use .isin to filter out your dataframe:

userids = ['225a33b9-2514-4686-a1e9-31279c66faee@tunnel.msging.net',
           'c360515f-8d8a-44b7-9097-f968c3e06579@tunnel.msging.net',
           '63167be5-8a1e-44e6-bf32-3900e048b899@tunnel.msging.net',
           '225a33b9-2514-4686-a1e9-31279c66faee@tunnel.msging.net']

prod = df[df['UserId'].isin(userids)]
Corralien
  • 109,409
  • 8
  • 28
  • 52