Get Google Trends Results Using Python

How to get rising related queries and top related queries from Google Trends by Pytrends (the unofficial API for Google Trends)

Sajid Hasan Sifat
Jul 29 · 3 min read
Image for post
Image for post
Photo by Rajeshwar Bachu on Unsplash
import pandas as pd
from pytrends.request import TrendReq
>pip install pandas
>pip install pytrends
pytrend = TrendReq(hl=’en-US’, tz=360)
# Create payload and capture API tokens. Only needed for interest_over_time(), interest_by_region() & related_queries()trendy_keywords = ‘Data Science’
kw_list = [trendy_keywords]
kw = trendy_keywords
pytrend.build_payload(kw_list)
pytrend.interest_over_time()
pytrend.interest_by_region()
# Related Queries, returns a dictionary of dataframesrelated_queries_dict = pytrend.related_queries()
print(related_queries_dict)
Image for post
Image for post
provided by author
# for rising related queries
related_queries_rising = related_queries_dict.get(kw).get(‘rising’)
# for top related queries
related_queries_top = related_queries_dict.get(kw).get(‘top’)
print(“**************** RISING RELATED KEYWORDS **************”)
print(related_queries_rising)
print(“**************** TOP RELATED KEYWORDS *******************”)
print(related_queries_top)
Image for post
Image for post
Image for post
Image for post
provided by author

Conclusion

Resources

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store