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)
Images
Plot outputs from the above usage example:
- Trends for 'olympics', before rescaling between overlaps:
- Trends after rescaling
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
Built Distribution
File details
Details for the file longtrends-0.5.tar.gz
.
File metadata
- Download URL: longtrends-0.5.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f82986d8b6fc654fa35fbe7458ae10ef6d239277aa304cecc703729a4cf0e4d |
|
MD5 | d09458e57759b85841b82eeb4d3e17c6 |
|
BLAKE2b-256 | 3e6aa1d83ffa7938244720c73a92d27e3407080f4fb47dc57f9c0c5c7bce8967 |
File details
Details for the file longtrends-0.5-py3-none-any.whl
.
File metadata
- Download URL: longtrends-0.5-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 149cd8f630cdf3c4a3a81384412474b1d276127a9d4b6d2b3c4f8f4b3760b11c |
|
MD5 | c7932e70fb3e8cd620307ee4fe2e9ad5 |
|
BLAKE2b-256 | 0d0babf815a4779fbfa6a9a25d482a26f62ab41cfdef9b59b27ddb8eb05600a4 |