Overview

The related_topics() function in the pytrends library allows you to retrieve related topics for a specific search term. By analyzing this data, you can discover new keywords and ideas that are relevant to your target audience, helping you to create engaging and relevant content.

In this tutorial, we will cover:

  1. Importing the necessary libraries
  2. Setting up the pytrends request
  3. Retrieving related topics data
  4. Analyzing the results

Retrieve Related Topics Data

First, we need to import the necessary libraries and set up our pytrends request.

from pytrends.request import TrendReq

# Set up pytrends request
pytrends = TrendReq(hl='en-US', tz=360)

Next, we’ll specify the search term for our request using the build_payload() function, and then retrieve related topics data using the related_topics() function.

keywords = ['Python']

# Build payload
pytrends.build_payload(keywords, timeframe='now 7-d', geo='')

# Retrieve related topics data
related_topics = pytrends.related_topics()

This will return a dictionary containing related topics data for the search term ‘Python’ over the past 7 days.

Analyzing the Results

Now, we can analyze the related topics data to identify new keywords and ideas for our content strategy.

# Extract the related topics for the keyword 'Python'
python_related_topics = related_topics[keywords[0]]['top']

# Display the top 10 rising related topics
print(python_related_topics.head(10))

This will display the top 10 rising related topics for the search term ‘Python’, providing valuable insights into new and emerging trends related to your keyword.

Conclusion

In this post, we’ve demonstrated how to use the related_topics() function in the pytrends library to investigate related topics for a given search term. By exploring this data, you can expand your keyword research and discover new opportunities to engage your target audience. This tutorial has covered the process of collecting and analyzing related topic data, from setting up the pytrends request to analyzing the results. Using these insights, you can inform your content strategy and boost your online presence.


NOTE : pytrends uses an unofficial API. Please use here for issues.

SAMPLE CODE : https://github.com/hobbyworker/google-trend-for-python