Question Regarding "7. Pandas Index Alignment" from "Exploring Data with pandas: Intermediate"

I was able to get the correct answers based on the Learning info for this lesson. I do need some clarification. I know the first answer is:

`previously_ranked = f500[f500["previous_rank"].notnull()]`

I was able to get the correct answer on my second attempt. What I’m trying to understand is when would the dataframe be called twice as well as using two sets of brackets? I only called the dataframe once with one set. Once I re-read the lesson, I made the fix. However, I might have overlooked somewhere how the answer’s syntax works and why it is the correct answer. Is it method chaining, which is why the answer is written that way?

[] is python’s syntactic sugar for __getitem__, usually, the input is either a number/slice (to indicate a position/range of positions in a sequence), a label (such as accessing from a pandas series), a boolean (to select or not select something). I wouldn’t say there is a general rule to when you use [] 2 times, but try to understand the code based on what is it doing, one way is to break down the steps and view the output. (type(), the values contained, and possibly id()).

So for this code, you can print

  1. f500["previous_rank"]
  2. f500["previous_rank"].notnull()
  3. f500[f500["previous_rank"].notnull()]

and observe what each step generates.

Then think, is it necessary to use 2 brackets? If yes, why. If no, is there any other possible way?
If don’t know other possible way, then it’s an opportunity to train googling skills, which would be something like “filter rows of pandas dataframe based on non null values in a specific column” to see how others may implement it in a different way.