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
.
Quick Start
from longtrends import LongTrend
from datetime import datetime
keyword = 'suncream'
# Create LongTrend object
longtrend = LongTrend(
keyword=keyword,
start_date=datetime(2018, 1, 1),
end_date=datetime(2022, 3, 31)) # use verbose=True for print output
# Build long-term trends
lt_built = longtrend.build()
# Plot
lt_built.plot(title=f"Google Trends: {longtrend.keyword}", figsize=(15, 3))
Under the hood
First, longtrends downloads overlapping trends.
from longtrends import rescale_overlaps, get_overlapping_trends, rescaled_longtrend
import pandas as pd
overlapping = get_overlapping_trends(
keyword=keyword,
start_date=datetime(2018, 1, 1),
end_date=datetime(2022, 3, 31),
verbose=True)
pd.concat(overlapping, axis=1).plot(figsize=(15,3), legend=False)
Next, i+1th overlap is rescaled to ith overlap.
rescaled = rescale_overlaps(overlapping)
pd.concat(rescaled, axis=1).plot(figsize=(15,3), legend=False)
Finally, a single long-term trend is picked.
rescaled = rescaled_longtrend(rescaled)
rescaled.plot(figsize=(15,3), title='Rescaled long-term trend')
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.6.tar.gz
.
File metadata
- Download URL: longtrends-0.6.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 690d9662d8075098f8b4b72a087e6363e7548d9c146637a94afa250999520c45 |
|
MD5 | 3156f3f6d00648e0c4cd302d1d196ef9 |
|
BLAKE2b-256 | f7331108ff974cf66fec670a3869146c92f91ffe387b3225d0208128c7da15de |
File details
Details for the file longtrends-0.6-py3-none-any.whl
.
File metadata
- Download URL: longtrends-0.6-py3-none-any.whl
- Upload date:
- Size: 5.6 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 | 25f1bc0025a1abcf9ce56ea9bde3e375b7b1cbfb2189e457a556a831a40d5147 |
|
MD5 | 6cbc3cd1408e3766aeeef7dbf0894da2 |
|
BLAKE2b-256 | 643d3dc219992c7f9c1d9758d3204f6c6e6a72c36ddbec40075d34067fb7fe2b |