Bulk Google Trends Data Automation With a Pseudo-API

For Google Colab notebooks, and a simple CSV with Column Header Keywords, and up to 50 topics. Adjust the timeframe as needed.

pip install pytrends

import pytrends
import io
from pytrends.request import TrendReq
import pandas as pd
from google.colab import  drive
from google.colab import files

uploaded = files.upload()

pytrend = TrendReq()
for keys in uploaded:
  name = keys
df2 = pd.read_csv(io.BytesIO(uploaded[name]))

topics = df2.Topic
dataframe = pd.DataFrame()
i = 0
for topic in topics:
  if isinstance(topic,str):
    pytrend.build_payload(kw_list=[topic], timeframe='today 12-m')
    data = pytrend.interest_over_time()
    df = pd.DataFrame(data)
    if i == 0:
      dataframe = df
      del dataframe['isPartial']
      i = i + 1
    keyword_colum = df[topic]
    dataframe[topic] = keyword_colum
dataframe.to_csv("keywords_trends.csv", encoding='utf-8-sig')

Special thanks to Fozan again for assistance.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply