【问题标题】:Writing consecutive dates in the excel file在excel文件中写入连续日期
【发布时间】:2022-01-14 03:21:45
【问题描述】:

我想在 excel 文件的列中写入连续的日期(例如 10,11,2022, 10,11.2024, 10,11,2026,.....),但我不知道该怎么做这在 Python 中?如果您能帮我解决这个问题,我将不胜感激,谢谢!

【问题讨论】:

    标签: python excel pandas date time-series


    【解决方案1】:

    date_rangeoffsets.DateOffset一起使用2年:

    first='2022-10-11'
    
    r = pd.date_range(first, periods=5, freq=pd.offsets.DateOffset(years=2))
    print (r)
    DatetimeIndex(['2022-10-11', '2024-10-11', '2026-10-11', '2028-10-11',
                   '2030-10-11'],
                  dtype='datetime64[ns]', freq='<DateOffset: years=2>')
    
    
    print (r.strftime('%m.%d.%Y'))
    Index(['10.11.2022', '10.11.2024', '10.11.2026', '10.11.2028', '10.11.2030'],dtype='object')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多