Search code examples
pythongoogle-trends

How to use the Google Trends historical trend data obtained using pytrends


I have managed to extract Google Trends historical trend data for given keywords using pytrends.

pytrends = get_pytrends()
keywords = {'q': 'chelsea', 'date' : 'now 12-H'}
print(json.dumps(pytrends.trend(keywords, return_type='json'), indent=4))

NOTE: The above data has been obtained for the last 12 hours.

The following section highlights the a short section of the output JSON data.

{
    "status": "ok",
    "sig": "707079741",
    "table": {
        "cols": [
            {
                "type": "date",
                "id": "date",
                "label": "Date",
                "pattern": ""
            },
            {
                "type": "number",
                "id": "query0",
                "label": "chelsea",
                "pattern": ""
            }
        ],
        "rows": [
            {
                "c": [
                    {
                        "f": "Jan 31, 2017, 02:08 PST",
                        "v": "2017-01-31"
                    },
                    {
                        "f": "13",
                        "v": 13.0
                    }
                ]
            },
            {
                "c": [
                    {
                        "f": "Jan 31, 2017, 02:16 PST",
                        "v": "2017-01-31"
                    },
                    {
                        "f": "13",
                        "v": 13.0
                    }
                ]
            },
            {
                "c": [
                    {
                        "f": "Jan 31, 2017, 02:24 PST",
                        "v": "2017-01-31"
                    },
                    {
                        "f": "13",
                        "v": 13.0
                    }
                ]
            },
...

It is clear that the above data refers to values of a table but I have no clue as to the definitions of values indicated by keys 'f' and 'v'. I am intending to use these data as part of a scoring calculation of the trending topics I extract from social networks (hashtags and etc.) but due to the lack of clarity of the meaning of indicated data, I am not sure how to use it. No accurate resources exist with regards to using these data.

This link about a similar, JavaScript library provides some useful information but the output I have received seems different.

How do I use these data effectively?


Solution

  • I went through Google Trends' official documentation and I came across this resource which defines how to read the search interest line graphs and news articles bar graphs. I believe the historical trend value corresponding to each time interval in the table result must be calculated based on the above values. This link directs you to a comprehensive documentation with regards to the calculations used when identifying trends.

    The pytrends documentation notes that the value generated is based on world as the location unless a particular country or region is specified. Thus, the above value corresponds to world level statistics.

    Note: Hopefully this answer provides an insight into to understanding the data extracted from Google Trends although I haven't found a way how to use the data, effectively. Hope this would be useful for future references to this question.