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.
Metadata
Release files for longtrends 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| longtrends-0.6.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| longtrends-0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.0 kB
Release files / longtrends-0.6.tar.gz
| Download URL | longtrends-0.6.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
690d9662d8075098f8b4b72a087e6363e7548d9c146637a94afa250999520c45
|
|
BLAKE2b-256 checksum How to use checksums |
f7331108ff974cf66fec670a3869146c92f91ffe387b3225d0208128c7da15de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|
Release files / longtrends-0.6-py3-none-any.whl
| Download URL | longtrends-0.6-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25f1bc0025a1abcf9ce56ea9bde3e375b7b1cbfb2189e457a556a831a40d5147
|
|
BLAKE2b-256 checksum How to use checksums |
643d3dc219992c7f9c1d9758d3204f6c6e6a72c36ddbec40075d34067fb7fe2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|