I have gone through Ambiguity in Pandas Dataframe / Numpy Array "axis" definition but it still does not resolve my confusion about the use of axis in pandas.
Lets say I have a dataframe df containing columns 'col1' and 'col2'. I want to keep rows where 'col1' is 1 and 'col2' is 0. If I run
df[df.apply(lambda x:(x['col1']==1) and (x['col2']==0))]
I get an error.
I have to pass axis=1
df[df.apply(lambda x:(x['col1']==1) and (x['col2']==0), axis=1)]
for it to work. That does not make sense to me. The function passed to apply is being applied to every row, so according to my mental model, axis should be 0.
How do I make sense of axis=1 in this example?