Skip to main content

A Python package to collect and analyze Google Trends data for US states.

Project description

GTUS - Google Trends for US States

The GTUS package is a Python library designed to collect Google Trends data for specified queries across various U.S. states. It provides functionality to handle multiple queries and states efficiently, while adhering to Google Trends API limitations.


Features

  • Collect trends for one or multiple states.
  • Batch processing of queries to avoid API limits.
  • Adjustable wait time between requests to manage rate limits.
  • Export collected data to Excel and JSON formats.
  • Access data in a consolidated pandas DataFrame for easy analysis.

Installation

To use the GTUS package, ensure you have the required dependencies installed. You can install them using pip:

pip install gtus

This will automatically install all required dependencies, including pytrends, pandas, and aiohttp.


Getting Started

Here's how to start using GTUS to collect Google Trends data.

Importing the Package

To use the GTUS package, import it as follows:

from gtus import GTUS

1. Collect Google Trends Data for US States

Collecting for One State

To collect data for a single state, create an instance of the GTUS class with the desired query and state:

from gtus import GTUS

queries = ["telemedicine", "remote work"]
states = ["TX"]
gtus = GTUS(queries, states, timeframe="2022-01-01 2023-01-01")

# Collect data
gtus.collect_all_trends()

Collecting for Multiple States

To collect data for multiple states, simply provide a list of states:

from gtus import GTUS

queries = ["telemedicine", "remote", "football", "dance"]
states = ["CA", "NY", "TX"]
gtus = GTUS(queries, states, timeframe="2020-01-01 2023-01-01")

# Collect data
gtus.collect_all_trends()

Collecting for All States

If no states are specified, GTUS will automatically collect data for all US states:

queries = ["remote work", "telehealth"]

# Initialize GTUS object
gtus = GTUS(queries=queries, timeframe="2022-01-01 2023-01-01", wait_time=15)

Modifying Wait Time

You can adjust the wait time between requests by specifying the wait_time parameter when creating the GTUS instance. This is useful for managing API rate limits:

gtus = GTUS(queries, states, wait_time=15)  # Set wait time to 15 seconds

Saving Data

Exporting to Excel

To save the collected data to an Excel file, use the export_to_excel method:

gtus.export_to_excel("google_trends_data.xlsx")

Exporting to JSON

To save the collected data to a JSON file, use the export_to_json method:

gtus.export_to_json("google_trends_data.json")

Accessing Data in Python

The data collected can be accessed in a consolidated pandas DataFrame. This allows for easy manipulation and analysis:

df = gtus.create_consolidated_dataframe()
print(df.head())

Example Output

The DataFrame will have the following structure:

date State telemedicine remote work football dance
2021-12-26 CA 72.0 62.0 59.0 68.0
2021-12-26 TX 73.0 59.0 67.0 70.0

Dependencies

  • pandas
  • pytrends
  • aiohttp
  • openpyxl

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.


License

This project is licensed under the MIT License. See the LICENSE file for more information.


Start exploring Google Trends data with GTUS today!

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

gtus-0.1.2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gtus-0.1.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file gtus-0.1.2.tar.gz.

File metadata

  • Download URL: gtus-0.1.2.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for gtus-0.1.2.tar.gz
Algorithm Hash digest
SHA256 31adcfcba520d6de454f12fb404fe9652327727b51642a87ae994390780cb5d2
MD5 0c13a3ff3c9569fdc03c2303687a02c6
BLAKE2b-256 bafbdd8fd284d19db26883f7fd8aaee88972383f67dfac22aca031698d774c91

See more details on using hashes here.

File details

Details for the file gtus-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gtus-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for gtus-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d47f50d27d27c7d7c5cab135031412746b78e60951e63fedcb698c777c84863
MD5 9d283b8ac18d1c9ab204f35450ba7cc2
BLAKE2b-256 9ca055ca5a90b5b1317104246bbed2dd2ee3fe610bc64b0f21967b63e9b3b3e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page