Pandas offset DatetimeIndex to next business if date is not a business day

后端 未结 3 932
醉梦人生
醉梦人生 2021-01-03 06:20

I have a DataFrame which is indexed with the last day of the month. Sometimes this date is a weekday and sometimes it is a weekend. Ignoring holidays, I\'m looking to offset

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 07:03

    You can add 0*BDay()

    from pandas.tseries.offsets import BDay
    df.index = df.index.map(lambda x : x + 0*BDay())
    

    You can also use this with a Holiday calendar with CDay(calendar) in case there are holidays.

提交回复
热议问题