Boolean filtering an Index type object?

Hi there,

I have a question about this line of code

cols_with_missing_vals = mvc.columns[mvc.isnull().sum() > 0]

on the following lesson page:

I get most of what’s going on, but one piece of it is unfamiliar because it seems like it’s filtering an Index type object in the same way that one would filter a Series, so I’m wondering if Index objects and Series can be thought of in the same way with regard to filtering. Here’s the code/question breakdown:

# Step 1) An Index object -- I get this
# Step 2) How the slice of the Index object works
    # Step 2a) Boolean filter of entire `mvc` DataFrame -- I get this
# Step 2b) Sum each of the columns of the boolean filtered DataFrame 
    # to see how many column entries are null.
    # Returns a Series -- I get this
    # Step 2c) Make a boolean filter 
    # to see which of the Series have > 0 missing values -- I get this
mvc.isnull().sum() > 0
# Step 3) Passing this boolean filter to a slice of an Index object -- THIS IS UNFAMILIAR TO ME
mvc.columns[mvc.isnull().sum() > 0]

Obviously, it works, so I’d like to better understand what’s going on:

A) Does filtering and slicing Index type objects work in the same way as filtering and slicing Series or DataFrame objects?

B) Are all iterables the same in this way?

Great that you have begun to ask questions to expand your views.
Behaviour of Python can be controlled by dunder methods. Whenever you can do something in a certain way, it’s because the author of the class has used a certain dunder method to make a certain syntactic sugar possible. You can read realpython or watch some pycon videos to get what it means
For indexing, [] is syntactic sugar for __getitem__, which means to let the user use [] on an object, the creator of the object/class just has to implement a def __getitem__ method in the class.

Thanks for the prompt response and reference. Very helpful.