Reputation: 1667
I have noticed some inconsistent behaviour in how axes are defined (as discussed in in this forum: What does axis in pandas mean?), and I just would like to make sure I understand correctly that:
For dropna
axis=0
means: the algorithm goes through each row and checks for na's, if there are any/all it deletes that row.
For any
axis=0
means: the algorithm goes through each column and checks for condition True, if there are any/all it deletes that column
So the definition of row and column are switched (although the pandas doc explains 'any' axis as {index (0), columns (1)}.
Is this correct?
Upvotes: 2
Views: 313
Reputation: 294258
Axis zero is the index. Axis one are the columns. That’s it.
The interpretation of why the different axis choices behave the way they do is confusing. It is my belief that it is consistent though.
For dropna
it refers to the axis from which keys will be dropped.
For any
, sum
, mean
, and many more, it refers to the axis over which we will evaluate the reduction function.
For apply
it refers to the axis that is used in each of the series objects that get passed to the function being applied.
For add
, mul
, etc. it refers to the axis that is used as a reference when adding a series to a dataframe.
You can make arguments why you may have made different choices. But I think the developers made good choices. If something specific confuses you, ask a question.
Upvotes: 1