我想在Google趋势历史数据中找到自相关。非正式的API使用了Pandas Dataframes,我决定为其使用其内置的自相关函数,代码如下:
from pytrends.request import TrendReq
z = ["animales"]
google_username = "[email protected]"
google_password = "xxxxxxxxx"
path = ""
pytrend = TrendReq(google_username, google_password, custom_useragent='')
pytrend.build_payload(kw_list=z, timeframe='today 5-y', geo='MX')
interest_over_time_df = pytrend.interest_over_time()
print(interest_over_time_df[z].autocorr(lag=1))
这以前已经起作用,并且不确定我做了什么更改,我的代码抛出以下错误:
Traceback (most recent call last):
File "C:/Users/Rafael/PycharmProjects/untitled/test.py", line 19, in <module>
print(interest_over_time_df[z].autocorr(lag=1))
File "C:\Users\Rafael\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'autocorr'
最佳答案
some_dataframe["col_name"]
返回Series
。 some_dataframe[["col_name"]]
返回DataFrame
。 autocorr
is a Series
function。
关于python - Pandas 自相关函数错误:“DataFrame”对象没有属性“autocorr”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44442358/