【问题标题】:Pytrends timezone (tz)Pytrends 时区 (tz)
【发布时间】:2021-05-31 10:33:25
【问题描述】:

我对 Pytrends,特别是 TZ 有点吃力。更改时区时,不会更改输出中的时间戳。

    pytrends = TrendReq(hl = 'en-US', tz = 120)
keywords = ['lei', 'lei code', 'legal entity identifier']

data = pytrends.get_historical_interest(keywords, year_start=2021, month_start=5, day_start=30,
 hour_start=0, year_end=2021, month_end=6, day_end=1, 
hour_end=0, geo='IE', gprop='', sleep=0)
data

输出:

date lei    lei code    legal entity identifier isPartial               
2021-05-31 07:00:00 54  0   0   False

2021-05-31 08:00:00 44  13  0   False

2021-05-31 09:00:00 33  0   0   False

2021-05-31 10:00:00 74  0   0   True

如果我再更改时区 (tz),则输出相同

        pytrends = TrendReq(hl = 'en-US', tz = 0)
    keywords = ['lei', 'lei code', 'legal entity identifier']
    
    data = pytrends.get_historical_interest(keywords, year_start=2021, month_start=5, day_start=30,
     hour_start=0, year_end=2021, month_end=6, day_end=1, 
    hour_end=0, geo='IE', gprop='', sleep=0)
    data

输出:

date lei lei code legal entity identifier isPartial


2021-05-31 07:00:00 54  0   0   False

2021-05-31 08:00:00 44  13  0   False

2021-05-31 09:00:00 33  0   0   False

2021-05-31 10:00:00 74  0   0   True

可能我错过了一些明显的东西,但是我怎样才能使时间随着时区而改变。 正在考虑只是滞后输出。

关于K

【问题讨论】:

    标签: python timezone google-trends


    【解决方案1】:

    Google 以 UTC 格式返回结果,您可以使用此代码将 UTC 转换为其他时区(例如 EST)

    from pytrends.request import TrendReq
    import pytz
    
    pytrends = TrendReq(hl = 'en-US', tz = 200)
    keywords = ['lei', 'lei code', 'legal entity identifier']
    
    data = pytrends.get_historical_interest(keywords, year_start=2021, month_start=5, day_start=30,
     hour_start=0, year_end=2021, month_end=6, day_end=1, 
    hour_end=0, geo='IE', gprop='', sleep=0)
    
    index = data.index
    data.index = index.tz_localize(pytz.utc).tz_convert(pytz.timezone('EST')).tz_localize(None)
    data
    

    您可以使用此获取时区列表

    pytz.all_timezones
    

    希望这能解决您的问题

    【讨论】:

      猜你喜欢
      • 2010-09-17
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 2015-05-16
      相关资源
      最近更新 更多