df.resample('M').sum() is called on a DataFrame whose date lives in an ordinary string column rather than the index. What happens?
Correct answer
C. A TypeError about the index, because resample needs a DatetimeIndex on the axis
14 views
C. A TypeError about the index, because resample needs a DatetimeIndex on the axis
14 views
resample operates on a time-based index, so the datetime column must first be made the index or passed with on='date' after pd.to_datetime. The 'M' rule labels each bin by month end, controlled by the label and closed arguments. Use .dt.to_period('M') when calendar-month grouping rather than timestamp binning is wanted.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.