Skip to main content

pytrendex

Code to generate a Google Trends Index

Installation

pip install pytrendex

Trendex

The main thrust of this package is a class Trendex. This class makes an index utilizing Google Trends from keywords.

Parameters

  • kw_list: list The list of keywords that will be searched. If larger than 5, will create benchmark term from the first term in the list.

  • geo: str The country or place the search is conducted in, see Trends documentation.

  • date_start: str, optional The data where the index starts in format: 'yyyy-mm-dd', if none provided, then does it at the cutoff days before the date end.

  • date_end: str, optional The data where the index ends in format: 'yyyy-mm-dd', if none provided, then defaults to current day.

  • frequency: str, optional The frequency of the index. Note that the index always pulls daily data, so collapsing into larger time-frames is done by averages ex-post.

  • gen_index: Binary, optional If true, then go ahead and instantiate class to generate indices. Default is True.

  • plot: boolean, optional If True, and gen_index is True, then it plots index. Default is true.

  • kw_list_split: boolean, optional If True then the max length for kw_list is 20 terms; after that it will split the search by using the "+" option for search terms (which acts as an "or" operator for google trends). Highly recommended to keep load down.

  • benchmark_select: boolean, optional If True then optimally search over timeframe for best benchmark phrase, see documentation for that function for description of how this is done. If False, then the benchmark will be the first term in the kw_list.

  • slowdown: boolean, optional If True then include time.sleep() at key moments to slow down the index. Currently defaults to random intervals of mean 5 or 7 seconds depending on where in the code. Remove this at your own peril (Google lockout).

  • seasonal_adjust: boolean, optional (default = True) If True, then seasonally adjust the series (recommended). Seasonally adjusted trends are always constructed and saved in trends_sa, but this incorporates them into the index that is automatically constructed.

Returns (back to class instance)

  • self.gti: Series (main output) This is the normalized indexes made from the underlying data. It is the main thing returned from this function.

  • self.trends: DataFrame (major output) It is the adjusted and combined series for each term searched. You could use this to plot individual keywords in the index. Will differ from raw_trends_adjusted if frequency is changed from daily.

  • self.trends_sa: DataFrame (major output) These are the trends seasonally adjusted; they are always returned.

  • self.raw_trends_adjusted: Dictionary (minor output) These are the adjusted (using overlapping timeframes) raw results for each term. Index of dictionary corresponds to index of timechunks. Could differ from trends if frequency is changed from daily.

  • self.raw_trends: Dictionary (minor output) These are the unadjusted raw results for each term. Note: Adjustment has still been made by the benchmark term for searches exceeding 5 terms.

  • self.adjustment_factors: Series (minor output) Returns the adjustment factors used on each overlapping segment. The adjustment is [term]_1/[term_2] * segment_2

Example

A use case example is provided here:

from pytrendex import Trendex

kw_list = ['Obama','Biden','Clinton','Warren','Trump','Bernie']
geo = 'US'
date_start = '2018-01-01'
frequency = 'weekly'

## Generating the indexes in two different ways
result = Trendex(kw_list=kw_list, geo=geo,
                  plot=False, date_start=date_start, frequency=frequency)

# A smaller index, here we create it in two steps (date start and end and frequency auto selected)
result2 = Trendex(['Obama','Trump'],geo='US',gen_index=False)
result2 = result2.make_index(plot=False)

## Analyzing the results

result.gti.plot() # creates a matplotlib plot of the index for us to look at
result2.trends_sa.plot() # plots the adjusted individual terms that make up the index

result.gti.to_csv('file.csv') # saves the index as a csv file

Metadata

Release files for pytrendex 5.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytrendex 5.0.0
File Size Uploaded Provenance Actions
pytrendex-5.0.0.tar.gz 9.1 kB Without provenance Details for pytrendex-5.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytrendex 5.0.0
File Interpreter ABI Platform Actions
pytrendex-5.0.0-py3-none-any.whl Python 3 none any Details for pytrendex-5.0.0-py3-none-any.whl

Total release size: 32.0 kB

Release files / pytrendex-5.0.0.tar.gz

Download URL pytrendex-5.0.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d9bd7cc54552ac78a5e04d5698924b3a362dcabc7d8492a1716be90b457a9325
BLAKE2b-256 checksum
How to use checksums
0820ea8e73a96592d1074835dbf09ab7f8075d67b629004098191b3d4842559e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

Release files / pytrendex-5.0.0-py3-none-any.whl

Download URL pytrendex-5.0.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb94a8f3a8f1013b9d28dd5fe31a850de508093319ddb91027a8804b96445b7e
BLAKE2b-256 checksum
How to use checksums
10df00836a8a101e0839b40e4dff14d987070bcbc417694f482187b086c0897b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

Security for pytrendex 5.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page