我想在Google趋势历史数据中找到自相关。非官方API使用Pandas Dataframes,我决定使用它的内置自相关函数,这里是代码:
from pytrends.request import TrendReq
z = ["animales"]
google_username = "xxx@gmail.com"
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'
答案 0 :(得分:3)
some_dataframe["col_name"]
返回Series
。 some_dataframe[["col_name"]]
会返回DataFrame
。 autocorr
is a Series
function