2017-03-04 135 views
2

我是python中使用pytrends模塊的新手,它允許您從Google Trends中提取數據。這個網站給出了一個很好的介紹模塊:https://github.com/GeneralMills/pytrendspython for Google Trends:使用interest_over_time時出現「ValueError:year超出範圍」

當使用pytrend.interest_over_time()時,我收到消息「ValueError:year is out of range」。我的代碼關鍵部分是:

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異常:今年是超出範圍」

+0

什麼是完整的錯誤? –

+0

就是這麼說。但看起來有點用處: - > 128 df ['date'] = pd.to_datetime(df ['time'],unit ='s') - > 276 unit = unit,infer_datetime_format = infer_datetime_format) –

回答

0

更改下列蟒蛇... \ LIB \站點包\ 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))) 

這爲我工作:)

1

我有同樣的問題,我在request.py添加astype('int')該管線180

來自:

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

到:

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

(not確定爲什麼我的線路號碼不同,但看起來像相同的問題)