0

I want to create a subset dataframe containing all the rows when the row 'Name' is Sam or Frank. I run the following code but it returns no data:

df.loc[(df["Name"] == 'Sam') & (df["Name"] =='Frank'), :]

How can I change the code to work?

theletz
  • 1,713
  • 2
  • 16
  • 22
Greg
  • 1
  • remove the ,: you should get your result. you could also use df.query('Name.isin(["Sam","Frank"])'). And yes, following on from Allolz comment, switch & to | – sammywemmy Feb 04 '20 at 21:45
  • 2
    Because it's impossible for the name to be simultaneously 'Frank' and 'Sam'. Use `.isin(['Frank', 'Sam'])` if you want either. – ALollz Feb 04 '20 at 21:46

0 Answers0