3 回答

TA貢獻1790條經(jīng)驗 獲得超9個贊
這是使用date和timedelta從datetime模塊解決您的問題的一種方法:
import pandas as pd
from datetime import date, timedelta
def next_day(begin, end):
"""Generator that returns the date and date's weekday name"""
while begin < end:
# If you need the first day
# uncomment the next line and comment the next yield one
# yield begin, begin.strftime('%A')
begin += timedelta(days=1)
yield begin, begin.strftime('%A')
begin = date(2018, 1, 1)
end = date(2019, 1, 10)
df = pd.DataFrame(next_day(begin, end), columns=['date', 'day name'])
print(df)
輸出:
date day name
0 2018-01-02 Tuesday
1 2018-01-03 Wednesday
2 2018-01-04 Thursday
3 2018-01-05 Friday
4 2018-01-06 Saturday
5 2018-01-07 Sunday
6 2018-01-08 Monday
7 2018-01-09 Tuesday
8 2018-01-10 Wednesday
9 2018-01-11 Thursday
10 2018-01-12 Friday
...
368 2019-01-05 Saturday
369 2019-01-06 Sunday
370 2019-01-07 Monday
371 2019-01-08 Tuesday
372 2019-01-09 Wednesday
373 2019-01-10 Thursday
添加回答
舉報