gpt4 book ai didi

python - 值错误 : You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

转载 作者:行者123 更新时间:2023-12-05 08:37:45 27 4
gpt4 key购买 nike

您好,在此先感谢您的帮助!

当我尝试执行从 GitHub 提取的时间序列分解时,出现ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None .我想我对错误有一个基本的了解,但是当我直接从计算机上的文件中提取数据而不是从 GitHub 中提取数据时,我没有得到这个错误。为什么只有当我从 GitHub 拉取数据时才会出现此错误?我应该如何更改我的代码才能不再出现此错误?

import pandas as pd
import numpy as np
%matplotlib inline
from statsmodels.tsa.seasonal import seasonal_decompose

topsoil = pd.read_csv('https://raw.githubusercontent.com/the-
datadudes/deepSoilTemperature/master/meanDickinson.csv',parse_dates=True)

topsoil = topsoil.dropna()
topsoil.head()

topsoil.plot();

result = seasonal_decompose(topsoil['Topsoil'],model='ad')


from pylab import rcParams
rcParams['figure.figsize'] = 12,5
result.plot();

最佳答案

试试这个:

import pandas as pd
import numpy as np
%matplotlib inline
from statsmodels.tsa.seasonal import seasonal_decompose

topsoil = pd.read_csv('https://raw.githubusercontent.com/the-datadudes/deepSoilTemperature/master/meanDickinson.csv',parse_dates=True)

topsoil = topsoil.dropna()
topsoil.head()

topsoil.plot();

topsoil['Date'] = pd.to_datetime(topsoil['Date'])
topsoil = topsoil.set_index('Date').asfreq('D')
result = seasonal_decompose(topsoil, model='ad')

from pylab import rcParams
rcParams['figure.figsize'] = 12,5
result.plot();

输出:

enter image description here

关于python - 值错误 : You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64617482/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com