Keyword Research with Python

Google Trends is a keyword research tool that helps the researchers, bloggers, digital marketers and some more people in the digital industry to find how often a keyword is entered into Google search engine over a given period. Google Trends is used for keyword research mostly is writing articles on hot topics. In this article, I’ll walk you through how to perform keyword research with python to find the hottest topics and keywords.

I will use the Google API to access Google trends which can be done by using the pytrends library in python. Python being a general-purpose programming language provides libraries and packages for almost every task. pytrends can be easily installed by using the pip command – pip install pytrends. I hope that you have easily installed this package, now let’s start with the task of keyword research with python.

Keyword Research with Python

You need to log in to Google first because, after all, we ask Google Trends for trending topics. For that, we need to import the method called TrendReq from the pytrends.request method:

import pandas as pd
from pytrends.request import TrendReq
import matplotlib.pyplot as plt
trends = TrendReq()Code language: Python (python)

Keyword Interest By Region

Let’s see the terms that are popular in the region around the world. I will choose the term to search for as “Data Science”:

trends.build_payload(kw_list=["Data Science"])
data = trends.interest_by_region()
print(data.sample(10))Code language: Python (python)
Data Science
Malaysia 29
Canada 35
Bolivia 0
Gabon 0
Panama 0
United Kingdom 30
Isle of Man 0
French Southern Territories 0
Eswatini 0
Israel 23

Values ​​are calculated on a scale of 0 to 100, where 100 is the most popular location as a fraction of the total searches for that location, a value of 50 indicates a location half as popular. Now let’s visualize the above search results to get better insights:

df = data.sample(15)
df.reset_index().plot(x="geoName", y="Data Science", figsize=(120,16), kind="bar") language: Python (python)
Keyword research with python

Keyword Research with Python for Daily Search Trends

Now let’s take a look at the top daily search trends around the world. To do this, we need to use the trending_searches () method:

data = trends.trending_searches(pn="india")
print(data.head(10))Code language: Python (python)
0 Indian flag
2 Independence Day speech
3 Happy Independence Day 2020
4 Happy Independence Day Images
5 Prashant Bhushan
6 Niharika Konidela
8 August 15
9 Flag

Google Keyword Suggestion

Now, let’s see how we can get the google keywords suggestion for keyword research with python. Keywords are those words that are mostly typed by users in the search engine to find about a particular topic:

keyword = trends.suggestions(keyword="Programming")
data = pd.DataFrame(keyword)
print(data.head())Code language: Python (python)
 mid                              title                  type
0    /m/01t6b                                  C  Programming language
1  /m/025sbhf               Software development                 Topic
2  /m/07sbkfb                               Java  Programming language
3     /m/0z5n  Application programming interface      Kind of software
4    /m/01mf_               Computer programming                 TopicCode language: PHP (php)

Also, Read – How to Earn Money with Programming?

I hope you liked this article on Keyword research with python. Feel free to ask your valuable questions in the comments section below. You can also follow me on Medium to learn every topic of Machine Learning. 

Also, Read – Bar Chart Race with Python.

Follow Us:

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1498

Leave a Reply