Usage of Boolean Indexing in the Pandas

Screen Link:

My Code:

large_revenue = f500["revenues"] > 100
negative_profits = f500["profits"] < 0
combined = large_revenue & negative_profits
big_rev_neg_profit = f500[combined, ["revenues", "profits"]]

What I expected to happen:
This one is taken from the Exploring Data with Pandas: Fundamentals (Part 8). As far as I understand, when we refer to the dataframe we have to use this format [row_name, column_name], however here we are using Boolean Indexing instead of providing the rows. Can you, please, tell me how Boolean indexing works in this situation and why do we put Boolean indexes instead of rows? This issue is also applicable to Numpy too.

Thank you in advance

What actually happened:

Replace this line with the output/error

Yes, instead of directly mentioning the rows, you can use boolean indexing to identify specific rows as well as indicated in the format above. You can also do the same for the columns.

This answer, while not exactly the same question, covers this a bit and also has a link that can help you better understand indexing in Pandas - What is the difference between these two code - #2 by the_doctor

1 Like

Thank you very much for your clarification! I sincerely appreaciate it :blush:

1 Like