【问题标题】:pytrends (Google Trends) daily freqpytrends(谷歌趋势)每日频率
【发布时间】:2018-04-09 12:09:37
【问题描述】:

我正在使用 pytrends python 包来拉搜索词的流行度。看起来默认频率是每周,但我需要每日数据。有没有可以调整的参数?我似乎找不到任何东西。这里有一些代码可以让你到达同一个地方...

import pytrends
import matplotlib.pyplot as plt
%matplotlib inline
from pytrends.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360)

pytrends.build_payload(["sp500", "dogs"], cat=0, timeframe='today 5-y', geo='', gprop='')

df = pytrends.interest_over_time()
df.tail()

如您所见,返回的数据帧每周采样一次。我如何才能获得 5 年前但每天的相同数据?

【问题讨论】:

  • google 趋势不提供超过 90 天的时间间隔的这种粒度的数据,但可以请求重叠间隔然后调整它们。我在 R github.com/321k/Google-Trends/blob/master/… 中找到了这个例子
  • 如果我的回答回答了你的问题,你能接受吗?这是社区的普遍做法。

标签: python pandas google-trends


【解决方案1】:

我访问这个问题是因为我正在搜索这个主题。截至今天(2019 年),pytrends 库有一个方法可以返回关键字的每日数据。

我建议查看他们的github repository

我应该指出,我没有测试我们可以获取多远的数据,但我确信文档中的某处有这些信息。

示例:

from pytrends.request import TrendReq
from pytrends import dailydata

df = dailydata.get_daily_data('cinema', 2019, 1, 2019, 10, geo = 'BR')

print(df)

输出

            cinema_unscaled  cinema_monthly isPartial  scale  cinema
date                                                                
2019-01-01               60             NaN       NaN    NaN     NaN
2019-01-02               76             NaN       NaN    NaN     NaN
2019-01-03               82             NaN       NaN    NaN     NaN
2019-01-04               71             NaN       NaN    NaN     NaN
2019-01-05              100             NaN       NaN    NaN     NaN
                    ...             ...       ...    ...     ...
2019-10-26               74            38.0       NaN   0.38   28.12
2019-10-27               74            33.0      True   0.33   24.42
2019-10-28               53            33.0       NaN   0.33   17.49
2019-10-29               37            33.0       NaN   0.33   12.21
2019-10-30               34            33.0       NaN   0.33   11.22

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    相关资源
    最近更新 更多