はじめに
pytrendsはGoogleトレンドのデータを取得するためのライブラリです。
インストール
pipenv
が導入されている前提で進めます。
$ pipenv install pytrends
get started
まずは、動かしてみます。今日本でトレンドになっている検索ワードを取得してみます。
from pytrends.request import TrendReq
pytrends = TrendReq(hl="ja-JP", tz=360)
print(pytrends.trending_searches(pn="japan"))
最近のトレンドを取得できました。
リアルタイムのトレンドを取得する
リアルタイムのトレンドを取得するには、realtime_trending_searches
を使います。
print(pytrends.realtime_trending_searches(pn="JP"))
返却値はpandas.DataFrame
です。
まとめ
Googleトレンドのデータを取得するためのライブラリpytrends
を使ってみました。
今ある技術を組み合わせることで、トレンドの分析や予測などに使えるかもしれません。