You can help contribute to this section by offering your own questions or feedback on the exercise!
Unlock your understanding, and share that aha moment with someone else! Teaching others and answering their questions is one of the best ways to learn.
Questions about formatting, syntax, or conceptual understanding are just a few avenues you may consider exploring.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
TL;DR : Basically, the Pandas Objects, i.e. Series, don’t have an inherent boolean value. A variable can either hold data or not (aka the None value); this means it’s truthy if it has data or falsy if it’s null. The Pandas Objects hold lots of data, so differentiating what makes these objects True or False becomes arbitrary. The Pandas creators are letting you decide what is true or false by requiring you to compare the obj’s elements versus the entire obj.
Why do both type brackets (() or ) work for the expressions below?
march_april = df[[df.month==‘March’] | [df.month==‘April’]]
march_april = df[(df.month==‘March’) | (df.month==‘April’)]
How do you type in the Bar symbol which stands for the “Or” operator if it’s not on your keyboard? The lesson won’t actually let you proceed without doing so. I had to click the get solution button to move forward but what I’m actually worried about is having to use it irl.
Do not understand the use of the operator or ‘|’ instead of and ‘&’ in the command: march_april = df[(df.month ==
‘March’) | (df.month == ‘April’)]
print(march_april)
Seems to me if one wants to display two rows the ‘&’ and operator should be used. But when the and ‘&’ operator is used, it displays only the column headers.
When we use AND (&) we want to see rows where the first statement ((df.month == ‘April’) and the second (df.month ==
‘March’) is TRUE together. Such a ROW must contain ‘April’ and ‘March’ at the same time, but it’s impossible. As a result - it displays only the column headers.
When we use OR (|) we want to see rows where ‘month’ is April OR March. There is such rows.