<jupyter_start><jupyter_text>Heat Map A heatmap is a two-dimensional graphical representation of data where the individual values that are contained in a matrix are represented as colors. The seaborn python package allows the creation of annotated heatmaps which can be tweaked using Matplotlib tools as per the creator’s requirement. Here, I have used twitter data about the frequency of tweets between January 2017 and September 2020 for 2020 american presidential election candidates <NAME> and <NAME>. This data can be found [here](https://www.kaggle.com/sgwood/biden-and-trump-tweets-201720). We start by importing all of the required libraries into the notebook.<jupyter_code># importing the libraries
import pandas as pd
import matplotlib.pyplot as plt
#installing seaborn beacase of lack of default istallation
!pip install seaborn
import seaborn as sns<jupyter_output>Collecting seaborn
  Downloading seaborn-0.11.1-py3-none-any.whl (285 kB)
[K     |████████████████████████████████| 285 kB 716 kB/s eta 0:00:01
[?25hRequirement already satisfied: pandas>=0.23 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.2.3)
Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.20.1)
Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.6.1)
Requirement already satisfied: matplotlib>=2.2 in /usr/local/lib/python3.9/site-packages (from seaborn) (3.3.4)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (1.3.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (2.4.7)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) ([...]<jupyter_text>Storing the data into a dataframe and taking a look at the imported data.<jupyter_code>data_url = "https://bit.ly/3cngqgL" # or "path/to/biden_trump_tweets.csv"
df = pd.read_csv(data_url, 
                 parse_dates=['date_utc'], 
                 dtype={'hour_utc':int,'minute_utc':int,'id':str}
                )
df.head()<jupyter_output><empty_output><jupyter_text>We now group the data and extract the relevant tweet information for the first candidate (now president!) <NAME>.<jupyter_code>g = df.groupby(['hour_utc','minute_utc','username'])
tweet_cnt = g.id.nunique()
jb_tweet_cnt = tweet_cnt.loc[:,:,'JoeBiden'].reset_index().pivot(index='hour_utc', columns='minute_utc', values='id')
# taking a look at a part of the data frame
jb_tweet_cnt.iloc[:10,:9]<jupyter_output><empty_output><jupyter_text>Adressing the null values and putting in substitutes for both the candidates in the following two code cells.<jupyter_code>jb_tweet_cnt.fillna(0, inplace=True)
# Ensure all hours in table
jb_tweet_cnt = jb_tweet_cnt.reindex(range(0,24), axis=0, fill_value=0)
# Ensure all minutes in table
jb_tweet_cnt = jb_tweet_cnt.reindex(range(0,60), axis=1, fill_value=0).astype(int) 
dt_tweet_cnt = tweet_cnt.loc[:,:,'realDonaldTrump'].reset_index().pivot(index='hour_utc', columns='minute_utc', values='id')
dt_tweet_cnt.fillna(0, inplace=True)
dt_tweet_cnt = dt_tweet_cnt.reindex(range(0,24), axis=0, fill_value=0)
dt_tweet_cnt = dt_tweet_cnt.reindex(range(0,60), axis=1, fill_value=0).astype(int)<jupyter_output><empty_output><jupyter_text>Plotting the heatmaps.<jupyter_code>sns.heatmap(dt_tweet_cnt)
plt.show()
sns.heatmap(jb_tweet_cnt)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13454545454545455, 'fraction_numerical': 0.03664335664335664, 'mean_word_length': 5.824427480916031, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '598176', 'license': 'MIT', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1288, 'n_words': 303, 'path': 'heat_map.ipynb', 'repo_name': 'icoder18/Data-is-Beautiful-Event-Resources', 'size': '3586'}