📄

Fetching Google Trends Data with pytrends

This article was automatically translated from theJapanese original by AI. It may contain translation errors.

This post was published over 2 years ago. Its content may be outdated.

Introduction

pytrends is a library for fetching data from Google Trends.

Installation

This assumes pipenv is already set up.

$ pipenv install pytrends

Get started

First, let’s try running it. Let’s fetch the search terms that are trending in Japan today.

from pytrends.request import TrendReq

pytrends = TrendReq(hl="ja-JP", tz=360)

print(pytrends.trending_searches(pn="japan"))

The output looks like this. console

We were able to fetch the recent trends.

To fetch real-time trends, use realtime_trending_searches.

print(pytrends.realtime_trending_searches(pn="JP"))

The return value is a pandas.DataFrame.

Screenshot

Summary

I tried out pytrends, a library for fetching Google Trends data. By combining it with existing techniques, you might be able to use it for trend analysis, prediction, and more.

Recent Articles

Network(beta)

Drag to move / Ctrl+wheel to zoom