1. Home
  2. Data Science
  3. Pandas
  4. On a Series with a DatetimeIndex, what does shift(1…

Added 30 Nov -0001

On a Series with a DatetimeIndex, what does shift(1, freq='D') do that shift(1) alone does not?

  1. It shifts the values one row down and leaves the index labels untouched
  2. It resamples the series to daily frequency before shifting the values
  3. It fills the vacated rows with the previous value instead of with NaN
  4. It shifts the index labels by a day, keeping values with their labels Correct answer

Correct answer

D. It shifts the index labels by a day, keeping values with their labels

14 views

MCQSEXAM

Explanation

With a freq argument, shift moves the index itself rather than the data, so each value keeps its own label offset by the given period and no NaN rows appear. Without freq, only the values move down and the first row becomes NaN. This distinction matters when aligning two time series that were sampled with a known reporting lag.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? 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