What is passed to the function in df.apply(f, axis=1)?
Correct answer
C. A Series for each row, indexed by the column labels
15 views
C. A Series for each row, indexed by the column labels
15 views
apply axis semantics: axis=1 iterates rows, so the callable receives each row as a Series keyed by column names, which makes row-wise logic readable through row['col']. axis=0 iterates columns and passes each column as a Series indexed by the row labels. Row-wise apply is convenient but far slower than vectorised operations on large frames.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.