2

我是在 python 中使用 pytrends 模块的新手,它允许您从 Google Trends 中提取数据。该站点很好地介绍了该模块:https ://github.com/GeneralMills/pytrends

使用 pytrend.interest_over_time() 时,我收到消息“ValueError:年份超出范围”。我的代码的关键部分是:

import pytrends
from pytrends.request import TrendReq

google_username = "" #my username
google_password = "" #my password

pytrend = TrendReq(google_username, google_password, custom_useragent=None)

pytrend.build_payload(kw_list=['Chipotle'], timeframe = 'today 5-y')
pytrend.interest_over_time()

然后我收到错误消息“ValueError:年份超出范围”

4

3 回答 3

1

我有同样的问题,我astype('int')在第 180 行添加了 request.py

从:

    df['date'] = pd.to_datetime(df['time'], unit='s')

至:

    df['date'] = pd.to_datetime(df['time'].astype('int'), unit='s')

(不知道为什么我的行号不同,但看起来是同一个问题)

于 2017-05-25T02:56:14.223 回答
0

在 python...\Lib\site-packages\pytrends\request.py 中更改以下内容

第 3 行:

from datetime import datetime

128号线附近:

#df['date'] = pd.to_datetime(df['time'],unit='s')
df['date'] = df['time'].map(lambda d: datetime.fromtimestamp(int(d)))

这对我有用:)

于 2017-03-11T17:12:50.923 回答
0

按照文档中的建议,您可以像这样转换时间戳:tstamp.to_datetime64().astype('O')

于 2020-09-21T10:20:17.470 回答