Mission 381 screen 12 challenge; more than one condition to filter results;

the given code was:

industry_usa = f500[“industry”][f500[“country”] == “USA”].value_counts().head(2)

I used the following code:

industry_usa2 = f500[“industry”][f500[“hq_location”] == “New York, NY” or f500[“hq_location”] == “Houston, TX”].value_counts().head(2)

i was trying to substitute hq_location for country and use or to add the multiple locations.

but it gives me an error.

could someone let me know how to add multiple conditions to my code using “or”, “and” or some other technique?

thank you;

Hi @saleemdar.dr

Two of the methods that can be applied here:

  • Use “|” for or and “&” for and conditions. Also, place each of your expressions in brackets (or may be try without them just to see what happens!). Like this:
df[(df.col1 == "this value") | (df.col1 == "that value")] 

df[(df.col1 == "this value") & (df.col2 == "diff value")]
  • Use Series.isin(<list like>) method. Pass the multiple values (for the same column) in a list-like format. This will also work as an or condition. Refer for more details
2 Likes

thank you for the reply
I’ll try it out…

thank you for the solution.

1 Like