Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
frankgenovaPython Web Development Techdegree Student 15,616 Points
How much data is missing from each row - what does axis = 1 mean?
In the notebook, there is a section called "How much data is missing from each row". The instructor uses the following code:
missing_data = np.sum(demo.isnull(), axis=1)
Per documentation, it looks like axis=None is the default. I'm not clear what the axis parameter does and why axis=1 was chosen.
Alex KoumparosPython Development Techdegree Student 36,886 Points
axis value represents the dimension of a multidimensional array.
In the case of this dataframe, we have two dimensions: columns and rows. Axis 0 (or None) refers to the columns, Axis 1 refers to the rows.
Consider this simplified version of the dataset:
Thus if we sum on axis 0/None, we see the number of null entries in each column:
ID 0 Age 0 Gender 0 Military 3 Citizenship 0 dtype: int64
Versus summing on axis 1, we see the number of null entries for each row:
0 1 1 0 2 1 3 1 4 0 dtype: int64
Hope that clears things up for you.