Skip to main content

Download long-term Google Trends

Project description

longtrends

A package to download long-term Google Trends.

Introduction

Google Trends, downloadable by API using pytrends, limits the time period which can be downloaded using a single request. Each request is scaled between 0 and 100, making comparison between different time periods difficult. This package automatically downloads overlapping trends and rescales them, providing trend data across a long-term period.

Installation

pip install longtrends

Requirements

Requires pytrends, installed automatically with pip.

Usage

from longtrends import rescale_overlaps, get_overlapping_trends
from datetime import datetime

# Get overlapping trends
olympics = get_overlapping_trends(
                                keyword='olympics',
                                start_date=datetime(2021, 7, 4),
                                end_date=datetime(2021, 8, 29),
                                days_delta=10)

# Rescale overlaps
olympics_rescaled = rescale_overlaps(olympics)

# Optionally, plot the two sets of trends for comparison
import matplotlib.pyplot as plt
import pandas as pd

def trends_plot(trends_list):

    """
    Args:
        trends_list (list): list of Series of trends, with scores as columns and dates as index

            each Series eg:

                date
                2016-04-10      44
                2016-04-17      44
                2016-04-24     100

    Returns:
        NoneType

    """

    # concat the trends together
    df = pd.concat(trends_list, axis=1)

    df.columns = [f'{df.columns[i]}_{i}' for i in range(df.shape[1])]
    df.plot.line(figsize=(15, 4))
    plt.ylabel('Score')
    plt.title('Google Trends over different time periods')
    plt.legend()
    plt.show()

# Plot overlapping trends
trends_plot(olympics)

# Plot rescaled trends
trends_plot(olympics_rescaled)

Disclaimer

This is not an official or supported product. It is provided without warranty under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

longtrends-0.4.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

longtrends-0.4-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page