在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ 給定起止日期提取整年,整月,零碎天數(shù)?【python實(shí)現(xiàn)】

給定起止日期提取整年,整月,零碎天數(shù)?【python實(shí)現(xiàn)】

給定一個起始日期,如20181026 給定一個結(jié)束日期,如20210203

如何提權(quán)這段時間內(nèi)的整年,整月,剩余天數(shù)?python如何實(shí)現(xiàn)?

條件:
begin_date=20181026

end_date=20210203
結(jié)果:
years=(2019,2020)
mouths = (201811,201812,202101)
days=(20181026,20181027,20181028,20181029,20181030,20181031,20210201,20210202,20210203)

回答
編輯回答
吢丕
import pandas as pd
begin_date='20181026'
end_date='20210203'
year = pd.date_range(begin_date, end_date, freq='Y')
print(year[1:].year.tolist())    # 年
month = pd.date_range(begin_date, end_date, freq='m')
print(month.strftime('%Y%m').tolist())    # 月
day = pd.date_range(begin_date, end_date, freq='D')
print(day.strftime('%Y%m%d').tolist())    # 日
2017年12月22日 00:41