Python Pandas


#1

Hi Codecademy,

I am working through the Inner Merge III with Python, specifically the exercise with Cool T-Shirts. Here is the question:

Cool T-Shirts Inc. thinks that they have more revenue in months where they sell more women’s t-shirts.

Select the rows of all_data where:

revenue is greater than target

AND

women is greater than men

Save your answer to the variable results

I have two proposals of which neither works:

  1. results = all_data[all_data.revenue > all_data.target and all_data.women > all_data.men]

  2. results = all_data[all_data.revenue > all_data.target] and all_data[all_data.women > all_data.men]

Could you please give me a nudge in the right direction?

Thanks

Eric


#2

Hi @ericsokolowski ,

Use the & operator instead of and. Within the square brackets, you need to place parentheses around each of the two comparisons that serve as the operands of the & operator, as follows …

results = all_data[(all_data.revenue > all_data.target) & (all_data.women > all_data.men)]