【问题标题】:Using pytrends to scrape coronavirus data使用 pytrends 抓取冠状病毒数据
【发布时间】:2020-07-02 17:34:18
【问题描述】:
kw = ['Coronavirus']

import pandas as pd
from pytrends.request import TrendReq
pytrends = TrendReq(hl='en us',tz=360)

kw = ['Coronavirus']
search_df = pytrends.get_historical_interest(kw)
search_df

以上是我的代码。我不确定如何解释我的输出?我还希望输出在数据方面会更丰富,例如指示该关键字的趋势。

感谢您的帮助!

【问题讨论】:

    标签: python web-scraping


    【解决方案1】:

    你的语法全错了。试试:

    from pytrends.request import TrendReq
    
    pytrend = TrendReq(hl='en-US', tz=360, retries=10, backoff_factor=0.5)
    
    search_df = pytrend.get_historical_interest(
        keywords=['Coronavirus'],
        year_start=2020,
        year_end=2020,
        month_end=4,
        month_start=2
    
    )
    print(search_df)
    
    pytrend.build_payload(kw_list=['Coronavirus'])
    
    # Interest Over Time
    interest_over_time_df = pytrend.interest_over_time()
    print(interest_over_time_df.tail())
    
    # Interest by Region
    interest_by_region_df = pytrend.interest_by_region()
    print(interest_by_region_df.head())
    

    主要来自https://github.com/GeneralMills/pytrends/blob/master/examples/example.py

    【讨论】:

      猜你喜欢
      • 2020-06-18
      • 2020-06-21
      • 2020-10-21
      • 2021-10-25
      • 2023-03-31
      • 2020-07-09
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      相关资源
      最近更新 更多