Determine if a day is a business day in Python / Pandas

后端 未结 6 1693
深忆病人
深忆病人 2021-02-13 23:06

I currently have a program setup to run two different ways. One way is to run over a specified time frame, and the other way is to run everyday. However, when I have it set to r

6条回答
  •  时光说笑
    2021-02-13 23:45

    There is builtin method to do this in pandas.

    For Pandas version <1.0

    from pandas.tseries.offsets import Day, BDay
    from datetime import date
    
    
    bdays=BDay()
    is_business_day = bday.onOffset(date(2020,8,20))
    

    For Pandas version >=1.1.0 (onOffset is deprecated)

    from pandas.tseries.offsets import Day, BDay
    from datetime import date
    
    
    bdays=BDay()
    is_business_day = bday.is_on_offset(date(2020,8,20))
    

提交回复
热议问题