user12379114
user12379114

Reputation:

How do I get the average output of google trends with pytrends?

I'm trying to get the average news results of five categories over the last year. In Google trends (https://trends.google.com/trends/explore?geo=US&gprop=news&q=Apples,Bananas,Oranges,Pears,Grapes) I get an average on the left with a bar graph giving Apples: 13, Bananas: 11, Oranges: 4, Pears: 4, Grapes: 9. But when I run this:

pytrend.build_payload(
    kw_list=["apples", "bananas", "oranges", "pears", "grapes"], gprop='news', timeframe='today 12-m', geo='US')
df = pytrend.interest_over_time()
interest_over_time_df = pytrend.interest_over_time()
print(interest_over_time_df.head())

This is my output:

            apples  bananas  oranges  pears  grapes isPartial
date                                                         
2020-07-19       0        0        0      0       0     False
2020-07-26      26        0        0      0       0     False
2020-08-02      25        0        0      0       0     False
2020-08-09       0       26        0      0       0     False
2020-08-16      26       26        0      0       0     False

How can I get just the average for each of these across the past year, and store those values?

Upvotes: 0

Views: 427

Answers (1)

Tejas
Tejas

Reputation: 401

The average that showing in side window is a straight average of values for each keyword, I don't think Pytrends library will provide that average for now, but you can calculate it by adding this line to your code

print(interest_over_time_df.mean())

Output:

apples     17.076923
bananas    12.942308
oranges     3.519231
pears       1.423077
grapes      8.961538
dtype: float64

enter image description here

Hope this will solve your issue

Upvotes: 1

Related Questions