Rafael Martínez
Rafael Martínez

Reputation: 335

Pandas autocorrelation function error: 'DataFrame' object has no attribute 'autocorr'

I want to find autocorrelation in Google Trends historical data. The unofficial API uses Pandas Dataframes for which I decided to use its built in autocorrelation function, here's the code:

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))

This has worked before and am not sure what did I change, my code throws the following error:

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'

Upvotes: 2

Views: 1314

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272687

some_dataframe["col_name"] returns a Series. some_dataframe[["col_name"]] returns a DataFrame. autocorr is a Series function.

Upvotes: 2

Related Questions