Select Rows with Logic II

Perhaps I’m used to languages i’ve learned in the past like Java but I don’t understand the logic in this code. The statement was that you wanted to "see how the number of clinic visits changed between March and April. To me, that would involve a mathematical operation to produce data showing the change. I dont get how the “I” (or) symbol does anything but grab these two months and pass it to a print argument. And I’m confused that this symbol allowed the printing of both data when I would think logically it would mean “print this OR this”. Thanks in advance.

df = pd.DataFrame([
  ['January', 100, 100, 23, 100],
  ['February', 51, 45, 145, 45],
  ['March', 81, 96, 65, 96],
  ['April', 80, 80, 54, 180],
  ['May', 51, 54, 54, 154],
  ['June', 112, 109, 79, 129]],
  columns=['month', 'clinic_east',
           'clinic_north', 'clinic_south',
           'clinic_west'])

march_april = df[(df.month == 'March') | (df.month == 'April')]

print(march_april)

Hello, @raydude6131.

Consider what type of object march_april is. Is it a function? Is it a data frame? If you print df what do you see versus when you print march_april?

1 Like