Apparently, this code is supposed to execute the function row-wise for a given dataset. However, according to my knowledge, row-wise operations are done by axis=0
, not axis=1
.
df.apply(func, axis=1)
Does the apply method somehow operate differently and I just need to know that this is an exception?
axis=0
means the functions works along the column and axis=1
means the functions works on the rows. For example
data = pd.DataFrame([[1,2], [3,4]])
data.sum(axis=0)
The result is
0 4
1 6
which is sum along the column