df.head(10(
Close year month day
Date
2014-12-31 31.4816 2014 12 31
2015-01-04 31.6416 2015 1 4
2015-01-05 31.8336 2015 1 5
2015-01-06 31.1168 2015 1 6
2015-01-08 31.7440 2015 1 8
2015-01-11 31.6736 2015 1 11
2015-01-12 32.4032 2015 1 12
2015-01-13 32.7744 2015 1 13
2015-01-14 33.9008 2015 1 14
2015-01-15 33.5936 2015 1 15
freq=None
所以我想向数据添加频率以进行季节性分解
result = seasonal_decompose(df['Return'], model='add')
但是,使用asfreq('D')
作为工作日周一至周五周,而我的数据是周日至周四周
所以我想知道我可以使用什么频率,或者如何将"D"频率调整为周日至周四周
使用此 https://www.geeksforgeeks.org/python-program-to-find-day-of-the-week-for-a-given-date/您可以找到每列的日期
# Python program to find the day of
# the week for a given date
import datetime
import calendar
def findDay(date):
born = datetime.datetime.strptime(date, '%d %m %Y').weekday()
return (calendar.day_name[born])
# Driver program
df['day'] = findDay(df['Date'])
之后,您可以应用熊猫value_counts()
并找到每天的频率。
df.day.value_counts()
希望它能回答你的问题。