justinzm / gopup

数据接口:百度、谷歌、头条、微博指数,宏观数据,利率数据,货币汇率,千里马、独角兽公司,新闻联播文字稿,影视票房数据,高校名单,疫情数据…
http://www.gopup.cn
2.55k stars 389 forks source link

请问谷歌指数能否选择地区? #20651

Open Preshire opened 3 years ago

Preshire commented 3 years ago

目前是否是显示中国地区的热度,请问能否选择国家呢?

以及如果是日为单位,请问该怎么设定呢?谢谢!

ShellMonster commented 3 years ago

+1,

这个我在源码中看到了有个“geo”的参数,是指定国别的,可否直接开放为可选参数,允许指定;

原代码:

def google_index(keyword="python", start_date="2019-12-01", end_date="2019-12-04"):
    """
    返回指定区间的谷歌指数
    :param keyword:
    :param start_date:  2019-12-10T10
    :param end_date:    2019-12-10T23
    :return:
    """
    try:
        pytrends = TrendReq(hl="en-US", tz=360)
        kw_list = [keyword]
        pytrends.build_payload(
            kw_list, cat=0, timeframe=start_date + " " + end_date, geo="", gprop=""
        )
        search_df = pytrends.interest_over_time()
        search_df['value'] = search_df[keyword]
        search_df['date'] = search_df.index
        res_df = search_df.drop(['isPartial', keyword], axis=1)
        return res_df
    except:
        return None