<jupyter_start><jupyter_text><NAME>, Data Explorer<NAME> (2762306) Donald Trump Approval Ratings (Job approval rating and trendline)https://projects.fivethirtyeight.com/trump-approval-data/approval_polllist.csvhttps://projects.fivethirtyeight.com/trump-approval-data/approval_topline.csv  Exploratory Data AnalysisMy idea is to examine the three datasets to see if there is any correlation or connection between President Trump's tweets and the lawsuits he and his company have been involved in.  Additionally, I would like to see if there is any correlation or connection between his tweets and his overall approval rating.<jupyter_code>import pandas as pd
import numpy as np
import datetime as dt
import seaborn as sns
import matplotlib.pyplot as plt
import math
from statistics import mean, stdev<jupyter_output><empty_output><jupyter_text>Read in the Data<jupyter_code>df_top = pd.read_csv("../data/external/approval_topline.csv")
df_poll = pd.read_csv("../data/external/approval_polllist.csv")
df_top.head()
df_poll.head()<jupyter_output><empty_output><jupyter_text>Plan to drop columns from approval_topline- president- approve_hi- approve_lo- disapprove_hi- disapprove_lo- timestamp Plan to drop columns from approval_pollist- president- pollster- grade- population- weight- approve- disapprove- multiversions- tracking- url- poll_id- question_id- timestamp *Additionally, will drop any rows from approval_pollist with fewer than 10k samples*<jupyter_code># Dropping columns from approval_topline
df_top = df_top.drop(axis=1, columns=['president', 'approve_hi', 'approve_lo', 'disapprove_hi', 'disapprove_lo', 'timestamp'])
df_top.head()
# Dropping columns from approval_pollists
df_poll = df_poll.drop(axis=1, columns=['president', 'pollster', 'grade', 'population', 'weight', 'approve',
                                        'disapprove', 'multiversions', 'tracking', 'url', 'poll_id','question_id',
                                        'influence', 'timestamp'])
df_poll.head()<jupyter_output><empty_output><jupyter_text>Seems like the createddate always appears a few days after the enddate of the poll, I'll keep this column for the datetime and drop the startdate and enddate.  I'll keep modeldate since that seems like it could match up with the approval_topline dataset<jupyter_code>df_poll = df_poll.drop(axis=1, columns=['enddate', 'startdate'])
df_poll.head()
# Dropping rows in df_poll that do not have >10k samplesize
df_poll_filtered = df_poll[df_poll['samplesize'] >= 10000]
df_poll_filtered.head()<jupyter_output><empty_output><jupyter_text>Breaking dates in both datasets out by month, day and year<jupyter_code>months = []
days = []
years = []

for row in df_top['modeldate']:
    month = row.split('/')[0]
    months.append(month)
    #print(month)
    day = row.split('/')[1]
    days.append(day)
    #print(day)
    year = row.split('/')[2].split(' ')[0]
    years.append(year)
    #print(year)
#Check that the splits I've created are the same size as the original data frame
print(len(days))
print(len(df_top['modeldate']))
df_top.insert(len(df_top.columns), 'M_Month', months, True)
df_top.insert(len(df_top.columns), 'M_Day', days, True)
df_top.insert(len(df_top.columns), 'M_Year', years, True)
df_top.head()
months = []
days = []
years = []

for row in df_poll_filtered['modeldate']:
    month = row.split('/')[0]
    months.append(month)
    #print(month)
    day = row.split('/')[1]
    days.append(day)
    #print(day)
    year = row.split('/')[2].split(' ')[0]
    years.append(year)
    #print(year)
c_months = []
c_days = []
c_years = []

for row in df_poll_filtered['createddate']:
    month = row.split('/')[0]
    c_months.append(month)
    #print(month)
    day = row.split('/')[1]
    c_days.append(day)
    #print(day)
    year = row.split('/')[2].split(' ')[0]
    c_years.append(year)
    #print(year)
#Check that the splits I've created are the same size as the original data frame
print(len(days))
print(len(df_poll_filtered['modeldate']))
print(len(c_days))
print(len(df_poll_filtered['createddate']))
df_poll_filtered.insert(len(df_poll_filtered.columns), 'M_Month', months, True)
df_poll_filtered.insert(len(df_poll_filtered.columns), 'M_Day', days, True)
df_poll_filtered.insert(len(df_poll_filtered.columns), 'M_Year', years, True)
df_poll_filtered.insert(len(df_poll_filtered.columns), 'C_Month', c_months, True)
df_poll_filtered.insert(len(df_poll_filtered.columns), 'C_Day', c_days, True)
df_poll_filtered.insert(len(df_poll_filtered.columns), 'C_Year', c_years, True)
df_poll_filtered.head()<jupyter_output><empty_output><jupyter_text>Save out edited data into data/processed for use in analysis notebook<jupyter_code>df_top.to_csv("../data/processed/topline.csv")
df_poll_filtered.to_csv("../data/processed/polling.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1294142085583714, 'fraction_numerical': 0.006439551308683008, 'mean_word_length': 5.42, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '530142', 'license': 'MIT', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1583, 'n_words': 391, 'path': 'notebooks/02-jimmy-wrangler-trump-approval.ipynb', 'repo_name': 'daltonhahn/eecs731-jimmy_wrangler', 'size': '4827'}