1 回答

TA貢獻1810條經驗 獲得超5個贊
然后我們需要創(chuàng)建范圍日期列explode
df.startdate=pd.to_datetime(df.startdate)
df.enddate=pd.to_datetime(df.enddate)
df['date']=[pd.date_range(x, y ) for x , y in zip(df.startdate, df.enddate)]
df=df.explode('date')
Out[169]:
startdate mwoutage enddate location date
0 2000-01-01 1000 2000-01-04 merica 2000-01-01
0 2000-01-01 1000 2000-01-04 merica 2000-01-02
0 2000-01-01 1000 2000-01-04 merica 2000-01-03
0 2000-01-01 1000 2000-01-04 merica 2000-01-04
1 2000-01-01 2000 2000-01-03 canadia 2000-01-01
1 2000-01-01 2000 2000-01-03 canadia 2000-01-02
1 2000-01-01 2000 2000-01-03 canadia 2000-01-03
添加回答
舉報