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 mvc.columns
# Step 2) How the slice of the Index object works # Step 2a) Boolean filter of entire `mvc` DataFrame -- I get this mvc.isnull()
# 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 mvc.isnull().sum()
# 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?