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
Built Distribution
File details
Details for the file longtrends-0.4.tar.gz
.
File metadata
- Download URL: longtrends-0.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f22209b45fc33d32d3a452feae5857be4f489ca0d4a55a9dd7cca91f3719b5be |
|
MD5 | 782952103f70f68ddcd3b80abc4a3b84 |
|
BLAKE2b-256 | e7599bb59c265644f62e42caf347998f162017700b3ee26d6ba8cfddf1f0b7bd |
File details
Details for the file longtrends-0.4-py3-none-any.whl
.
File metadata
- Download URL: longtrends-0.4-py3-none-any.whl
- Upload date:
- Size: 5.1 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 | ee89730e875a99e5c3f6d954d8bb239cbef03dfcdc08728d9645b5ab3958b2bc |
|
MD5 | 172fa16f064edd357d907c85d057cd20 |
|
BLAKE2b-256 | 52ea763b159977ac26271258bde416e6885c68e2d644da70464a0b284732141f |