Introduction To Pandas | Dataquest
motor_bool = f500['industry']=='Motor Vehicles and Parts'
motor_countries = f500.loc[motor_bool, 'country']
What I expected to happen:
I understand how the code worked. my query is that the output has 2 columns - country and industry - shouldn’t it be df type rather series type ? Isn’t a series suppose to have only 1 column ?
What actually happened:
Replace this line with the output/error
But, the output does not have two columns.
The first line of code is returning a Series with one column that has Boolean values. It’s a Series that tells us whether the Index corresponds to that particular industry or not. It’s not giving us rows corresponding to
industry. It’s only giving us rows with
False values depending on what meets the condition.
And because it’s a Boolean column/Series, when used by
loc on the
country column, it extracts rows from the
country column where the rows were
This is what that Mission’s content is trying to teach us as well. How Boolean indexing works.
You can read more about pandas.DataFrame.loc — pandas 1.3.1 documentation to see how it handles that Boolean input.
motor_countries has only one column -
Thanks . Got it . Output is 1 column i.e. country . Boolean mask is not an ouput.