<jupyter_start><jupyter_text>Whole30 Twitter Hashtags Trending in the US Within the Last 30 Days<jupyter_code># Import Dependencies
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import json
import pprint
import tweepy
import geocoder
import gmaps

# Import Twitter API Keys
from twitter_api import api_key, api_key_secret, access_token, access_token_secret

# Initialize Tweepy
auth = tweepy.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
# Base URL for Collecting 30-Day Endpoint (API Data)

from requests_oauthlib import OAuth1

# Get Data About Trending Diet Trends on Twitter: Whole30
url = "https://api.twitter.com/1.1/tweets/search/30day/DataAnalyticsProject.json"
auth = OAuth1(api_key, api_key_secret, access_token, access_token_secret)

# Whole30 API Requests
url_params = {'query': 'place_country:us #whole30'}
r = requests.get(url, auth=auth, params=url_params)
# Set Up Lists to Hold Reponse Info
whole30_location_list = []
whole30_location_dict = {}

# Set Counter to 0
count = 0

# Loop Through Tweets & Perform a Request for Data on Each
for tweet in r.json()["results"]:
    
    try:
        # Get & Print Location of Tweets
        user_name = tweet["user"]["screen_name"]
        location = tweet["user"]["location"]
        tweet_location = tweet["place"]["full_name"]
        lat, lng = geocoder.arcgis(tweet_location).latlng
        print(f"The user, {user_name}, is located in {tweet_location}, {lat}, {lng}")

        # Build Dictionary
        whole30_location_dict = {
             "user": user_name,
             "tweet_location": tweet_location,
             "lat": lat,
             "lng": lng
        }

        # Add Dictionary to List
        whole30_location_list.append(whole30_location_dict)
        
        # Increment Counter by 1
        count += 1
        
    except:
         continue

print(count)

# Create DataFrame
whole30_location_df = pd.DataFrame(whole30_location_list)
whole30_location_df
# Drop NaN's
whole30_data_split_no_missing = whole30_location_df.dropna()
whole30_data_split_no_missing.head()
# Create Open Columns
whole30_data_split_no_missing["state"] = ""
whole30_data_split_no_missing["city"] = ""
whole30_data_split_no_missing

# Split City & State
whole30_data_split_no_missing[["city", "state"]] = whole30_data_split_no_missing["tweet_location"].str.split(",", expand=True)
whole30_data_split_no_missing.head()
# Groupby "state" & Get Mean (Average) Location from Each state
locations = whole30_data_split_no_missing.groupby("state").mean()
locations.head()
# Value Count Each "state" (Total Tweets per State) & Sort Index by Alphabetical Order to Align with Locations
location_counts = whole30_data_split_no_missing["state"].value_counts()
reorganized_location_count = location_counts.sort_index()
reorganized_location_count
# Plot Heatmap
fig = gmaps.figure()

# Create Heat Layer
heat_layer = gmaps.heatmap_layer(locations, weights=reorganized_location_count, dissipating=False, max_intensity=10, point_radius=1)

# Add Layer 
fig.add_layer(heat_layer)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09191408717624763, 'fraction_numerical': 0.019898926089703096, 'mean_word_length': 4.716606498194946, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '318334', 'license': 'MIT', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1026, 'n_words': 250, 'path': 'Diet Twitter API (Whole30).ipynb', 'repo_name': 'bigbluey/Trending-Diets-of-Twitter-Users', 'size': '3166'}