Pandas add one day to column

后端 未结 6 1851
情歌与酒
情歌与酒 2020-12-24 05:10

I need to add 1 day to each date I want to get the begining date of the following month eg 2014-01-2014 for the 1st item in the dataframe. Tried:

montdist[\         


        
6条回答
  •  失恋的感觉
    2020-12-24 05:38

    As far as I can tell tshift is a bit faster than doing math such as + pd.DateOffset etc. Of course it only applies to Series or Dataframe indices, not columns.. but you could do:

    df['newdate'] = pd.Series(index=df.index).tshift(periods=1, freq='D').index
    

    If your df is large, this may shave off half the time - at least it did for me, which is why I'm using it.

提交回复
热议问题