Overview

The multirange_interest_over_time() function in the pytrends library allows you to retrieve the interest in specific keywords over multiple time ranges. By analyzing this data, you can gain insights into how the interest in a keyword has evolved over different periods, helping you to make informed decisions about your content strategy and marketing efforts.

In this tutorial, we will cover:

  1. Importing the necessary libraries
  2. Setting up the pytrends request
  3. Building the list of time ranges
  4. Retrieving multi-range interest over time data
  5. Analyzing the results

Building the List of Time Ranges

First, we need to create a list of time ranges for which we want to analyze the interest in our keywords. In this example, we will create a list of two time ranges

time_ranges = [
    '2022-09-04 2022-09-10',
		'2022-09-18 2022-09-24',
]

Retrieve Multi-Range Interest Over Time Data

Next, we need to import the necessary libraries, set up our pytrends request, and retrieve the multi-range interest over time data for our keywords and time ranges.

from pytrends.request import TrendReq

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

# Define the list of keywords
keywords = ['pizza', 'bagel']

# Build the payload
pytrends.build_payload(keywords, timeframe=time_ranges)

# Retrieve multi-range interest over time data
interest_over_time_data = pytrends.multirange_interest_over_time()

This will return a dictionary containing the interest over time data for our keywords across the specified time ranges.

Analyzing the Results

Now, we can analyze the multi-range interest over time data to understand the performance and popularity of our keywords across different periods.

# Display the interest over time data
print(interest_over_time_data)

This will display the interest over time data for each time range, providing valuable insights into the performance and popularity of our keywords across different periods.

Conclusion

In this post, we’ve demonstrated how to use the multirange_interest_over_time() function in the pytrends library to analyze the interest in specific keywords over multiple time ranges. By analyzing this data, you can gain a more comprehensive view of trends and understand how the interest in a keyword has evolved over different periods. This information can help you make informed decisions about your content strategy, marketing efforts, and even product development. By harnessing multi-range interest over time analysis, you can stay ahead of the competition and ensure that your content and products remain relevant and appealing to your target audience.


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

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