1. Home
  2. Data Science
  3. Pandas
  4. What is passed to the function in df.apply(f, axis=1)?

Added 30 Nov -0001

What is passed to the function in df.apply(f, axis=1)?

  1. A NumPy array of the whole frame
  2. A tuple of the row values in column order
  3. A Series for each row, indexed by the column labels Correct answer
  4. A Series for each column, indexed by the row labels

Correct answer

C. A Series for each row, indexed by the column labels

15 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs