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

后端 未结 3 934
醉梦人生
醉梦人生 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:23

    Using DataFrame.resample

    A more idiomatic method would be to resample to business days:

    df.resample('B', label='right', closed='right').first().dropna() 
    
                  A
    2015-04-30  0.0
    2015-06-01  0.0
    2015-06-30  0.0
    

提交回复
热议问题