GeoPopularity of Governors

by Talha Oz & Manqi Li

This notebook is to report some descriptive statistics on our U.S. Governors dataset. Governors' Twitter account handles are retrieved from https://twitter.com/gov/lists/us-governors/members using DD-CSS (this website allows downloading the info in CSV; disclaimer: I built the website).


In [2]:
import pandas as pd
import math
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')

In [3]:
# read and sort by number of followers
df = pd.read_table('../data/tw_gov.csv',parse_dates=['created_at'])
df = df.sort(columns='followers')
df
# Just to clarify the meanings of two potentially ambiguous field names:
# friends: number of people followed
# statuses: total number of tweets + retweets


Out[3]:
id screen_name name location description created_at friends followers statuses favorites
3 2666591852 NDGovDalrymple Jack Dalrymple Bismarck, ND Jack Dalrymple is the 32nd Governor of the gre... 2014-07-21 17:21:21 26 332 156 19
0 2916915026 GovHawaii HI Governor's Office Honolulu, HI The Official Twitter of Hawaii's Office of the... 2014-12-02 21:37:45 444 599 117 32
2 2891165960 GovRicketts Gov. Pete Ricketts NaN 40th Governor of Nebraska 2014-11-05 21:15:44 1 740 39 4
1 2915095729 AkGovBillWalker Governor Bill Walker Alaska Official Twitter page of Governor Bill Walker. 2014-11-30 21:47:17 33 985 106 4
4 2303719598 GovMattMead Governor Matt Mead Wyoming Official Twitter Account of Governor Matt Mead... 2014-01-21 21:14:54 17 1341 206 0
9 637143497 Governor_LePage Paul R. LePage Augusta, Maine The official tweets of Governor Paul LePage. ... 2012-07-16 17:40:36 253 4111 1566 31
11 280121510 ChangeMaryland Change Maryland Annapolis, MD Bringing fiscal restraint & common sense to MD... 2011-04-10 17:42:54 967 5465 5253 4872
27 111721601 GovernorBullock Steve Bullock Helena, MT I am proud to serve as Montana's 24th Governor... 2010-02-05 23:11:56 316 5564 2876 52
10 607332953 GovTomblin Governor Tomblin NaN The official Twitter account of West Virginia ... 2012-06-13 16:08:01 98 6038 1671 0
12 269992801 AsaHutchinson Gov. Asa Hutchinson Arkansas Husband of 41 yrs, Dad of 4, Papaw of 5. Lifel... 2011-03-21 20:32:54 475 6761 1725 72
14 234406945 SDGovDaugaard Gov. Dennis Daugaard South Dakota Gov. Dennis Daugaard is the 32nd Governor of S... 2011-01-05 15:49:32 586 7142 3755 4
8 946549322 GovernorHassan Gov. Maggie Hassan Concord, NH Official Twitter account of the Office of New ... 2012-11-13 21:27:37 527 8379 1645 0
44 20217019 dougducey Doug Ducey Arizona, USA Governor of Arizona 2009-02-06 04:35:14 1155 9586 2472 444
5 1321432124 WolfForPA Tom Wolf Pennsylvania Official account of Tom Wolf for Governor. Twe... 2013-04-02 00:29:01 533 10187 1581 131
41 36396752 ButchOtter Idaho Governor Boise, Idaho, USA If you are having trouble with this account pl... 2009-04-29 16:17:00 1686 10652 1011 0
13 240778059 GinaRaimondo Gina Raimondo Providence, RI Governor of Rhode Island dedicated to moving R... 2011-01-20 18:34:27 6291 11006 1459 49
22 208931294 GovSandoval Governor Sandoval Carson City, NV Governor of Nevada 2010-10-28 06:14:15 1457 11356 1381 91
31 89193992 govsambrownback Sam Brownback Topeka, Kansas Official Twitter page for Sam Brownback, Gover... 2009-11-11 14:18:51 342 11728 2148 29
17 231854033 GovPeterShumlin Peter Shumlin Montpelier, VT 81st Governor of Vermont. #vtforward 2010-12-29 17:02:05 1431 13126 6564 7
35 60688326 GovHerbert Gary R. Herbert Utah Proudly serving as the 17th Governor of the Gr... 2009-07-27 19:38:06 386 13827 2956 135
36 57963724 Gov_Martinez Susana Martinez Santa Fe, NM Governor of New Mexico. Please visit my Facebo... 2009-07-18 16:01:12 40 13874 574 0
32 84406725 TerryBranstad Terry Branstad Iowa This is the official Twitter account for Iowa ... 2009-10-22 19:45:32 1040 14696 6136 16
6 1077214808 GovInslee Governor Jay Inslee Olympia, WA Governor of WA. Tweets on innovation, jobs, ed... 2013-01-10 17:38:35 481 15530 1845 1650
18 231592153 PhilBryantMS Phil Bryant Mississippi A strong fiscal conservative dedicated to effi... 2010-12-28 23:30:49 851 18261 3280 144
7 1004855106 BruceRauner Bruce Rauner Illinois Diana's husband, proud Dad of six, now Governo... 2012-12-11 20:49:43 64 19654 1489 6
19 217416964 GovernorDeal Governor Nathan Deal NaN Governor Deal is the 82nd Governor of Georgia. 2010-11-19 13:36:16 273 20108 1359 91
40 37656339 GovSteveBeshear Steve Beshear Frankfort, KY Governor of the Commonwealth of Kentucky 2009-05-04 13:12:25 94 20110 2531 9
33 69427169 GovKitz John Kitzhaber Salem, Oregon Official tweets from Governor Kitzhaber. Welco... 2009-08-27 22:40:05 3801 20809 3925 6
23 194233791 GovMaryFallin Governor Mary Fallin Oklahoma Official Twitter account of Oklahoma Governor ... 2010-09-23 19:06:46 263 20880 3413 109
37 48724141 GovernorMarkell Gov. Jack Markell Delaware Governor of #Delaware who signs his tweets -JM. 2009-06-19 14:47:58 8324 20894 7011 1266
42 34308692 GovJayNixon Governor Jay Nixon NaN Official Twitter feed of Missouri Governor Jay... 2009-04-22 15:53:51 164 22524 2936 2
28 104198706 GovernorVA Terry McAuliffe Richmond, Va Official account for Virginia Governor Terry M... 2010-01-12 16:02:16 295 22611 2886 1
34 66602794 PatMcCroryNC Pat McCrory North Carolina Governor of the State of North Carolina 2009-08-18 05:08:47 380 27965 2807 1
38 39525554 GovernorBentley Gov. Robert Bentley Montgomery, AL Governor of Alabama. I will not accept a salar... 2009-05-12 15:44:35 400 29422 4030 33
20 216481299 GovMarkDayton Governor Mark Dayton Saint Paul, MN Check here for updates from the Office of Gove... 2010-11-16 21:08:36 5577 34392 2882 0
25 117839957 hickforco John Hickenlooper Colorado Official Twitter account for former geologist,... 2010-02-26 19:57:34 155 41798 1726 25
26 113036476 onetoughnerd Governor Rick Snyder NaN Governor of Michigan and self-proclaimed nerd.... 2010-02-10 13:59:40 322 42558 5171 99
43 26103389 BillHaslam Gov. Bill Haslam Tennessee Governor of Tennessee. 2009-03-23 22:12:06 8006 44541 1317 0
15 234141596 GovMalloyOffice Governor Dan Malloy Hartford, CT Official account of the Office of Connecticut ... 2011-01-04 23:13:19 759 45679 7758 34
24 131546062 FLGovScott Rick Scott The Sunshine State Florida's 45th Governor - My goal is to turn o... 2010-04-10 16:03:04 5756 53922 2967 2
49 15985455 GovPenceIN Governor Mike Pence Indiana Serving Hoosiers in all corners of the state a... 2008-08-25 18:52:42 791 56825 5991 190
29 90651198 GregAbbott_TX Greg Abbott Austin, TX Texas Governor Greg Abbott's Personal Twitter ... 2009-11-17 15:27:41 2899 58374 5718 50
47 18020081 JohnKasich John Kasich Westerville, Ohio Husband, Dad, and Governor of Ohio. 2008-12-10 14:33:27 8847 67029 4253 1
39 37666984 nikkihaley Nikki Haley South Carolina Governor of South Carolina 2009-05-04 14:10:21 9 98004 3467 13
21 213795411 GovWalker Governor Walker Wisconsin Official Twitter Account of the 45th Governor ... 2010-11-09 20:35:32 215 100413 6470 3
46 18023868 MassGovernor Charlie Baker Massachusetts Official account of Governor Charlie Baker of ... 2008-12-10 17:06:17 11154 117246 4893 1
16 232268199 NYGovCuomo Andrew Cuomo New York Official Twitter account for the Governor of N... 2010-12-30 17:54:04 471 145605 12789 1051
48 17078632 BobbyJindal Gov. Bobby Jindal Baton Rouge, LA The Official Bobby Jindal Twitter Page 2008-10-31 01:35:15 21007 174123 1942 0
30 90484508 GovChristie Governor Christie Trenton, NJ Official Twitter Account of the 55th Governor ... 2009-11-16 21:08:09 595 505401 7015 5
45 19418459 JerryBrownGov Jerry Brown California On Facebook at: http://t.co/ZhAotX27jb 2009-01-23 22:42:45 32 1046725 1928 77

In [4]:
df.to_csv('../data/tw_gov2.csv',index=False)

In [3]:
df = pd.read_csv('../data/governors-challengers.csv')
gov = pd.read_table('../data/tw_gov.csv',usecols=['screen_name','followers'])
gov = gov.rename(columns={'screen_name':'twgov','followers':'folgov'})
df = df.merge(gov)
df['folnorm'] = df['folgov'] / df['population']

In [4]:
ax = df.plot(x='folnorm', y='folgov', kind='scatter', figsize=(15,15),logy=True,logx=True,
            xlim=(df.folnorm.min(),df.folnorm.max()),ylim=(df.folgov.min(),df.folgov.max()*1.2))
df.apply(lambda x: ax.annotate(x['state'], (x['folnorm'],x['folgov']),
            xytext=(-40, 7), textcoords='offset points'), axis=1);
ax.set_xlabel("Follower numbers normalized by his/her state population",fontsize=14);
ax.set_ylabel("Actual number of Twitter followers",fontsize=14);
ax.set_title('Twitter Followers of Incumbent U.S. State Governors',fontsize=18);
x = df.folnorm
y = df.folgov
logx = np.log(x)
logy = np.log(y)
coeffs = (slope, intercept) = np.polyfit(logx,logy,deg=1)
poly = np.poly1d(coeffs)
yfit = np.exp(poly(logx))
plt.plot(x,yfit,'-.')
formula = 'log(y) = {:2.2f}*log(x) + {:2.2f}'.format(slope,intercept)
plt.legend([formula],loc=2)
ax.text(0.01,0.95,'Correlation between followers and state population (p) : '+
        '{:2.2f}'.format(df[['folgov','population']].corr().ix[0,1]),
         horizontalalignment='left',verticalalignment='top',
       transform=ax.transAxes,fontsize=12)
ax.text(0.05, 0.30,formula,transform=ax.transAxes,rotation=33);



In [5]:
# Beware, the y-axis is in log-scale (see the table above for exact numbers of followers where min. is ~300 and max is ~1M)
df = df.sort(columns='folgov',ascending=False)
df.plot(x='state',y='folgov', title='Twitter Follower Counts of U.S. State Governors',
        kind='bar', legend=False, figsize=(16,4),logy=True,ylim=(1,1500000));
plt.xlabel('Incumbent Governors')
plt.ylabel('Number of Twitter Followers')


Out[5]:
<matplotlib.text.Text at 0x8b06320>

In [6]:
# Beware, the y-axis is in log-scale (see the table above for exact numbers of followers where min. is ~300 and max is ~1M)
df = df.sort(columns='folnorm',ascending=False)
df['folnorm'] = df.folnorm * 10**7
df.plot(x='state',y=['folnorm','folgov'], title='Normalized Twitter Followers of U.S. State Governors',
        kind='bar', legend=False, figsize=(16,4),logy=True);
plt.xlabel('Incumbent Governors')
plt.ylabel('Twitter Follower Rate Normalized by State Population')


Out[6]:
<matplotlib.text.Text at 0xa106da0>

In [7]:
df = pd.read_csv('../data/governors-challengers.csv')
gov = pd.read_table('../data/tw_gov.csv',usecols=['screen_name','followers'])
gov = gov.rename(columns={'screen_name':'twgov','followers':'folgov'})
df = df.merge(gov)

ch = pd.read_table('../data/tw_ch.csv',usecols=['screen_name','followers_count'], encoding='utf-16')
ch = ch.rename(columns={'screen_name':'twch','followers_count':'folch'})
df = df.merge(ch)
# states whose incumbent governors have less followers than their challengers...
df[df['folch']>df['folgov']]


Out[7]:
state party since twgov twch shareGov shareCh voterCnt population folgov folch
1 Alaska I 2014 AkGovBillWalker SeanParnellAK 48.1 46.4 243597 736732 985 6198
9 Hawaii D 2014 GovHawaii DukeAiona2014 49.5 37.1 366125 1419561 599 4558
11 Illinois R 2015 BruceRauner GovernorQuinn 50.8 45.9 3508302 12880580 19654 20236
24 Nebraska R 2015 GovRicketts Vote4Chuck 57.6 38.9 524068 1881503 740 2169
31 North Dakota R 2010 NDGovDalrymple TaylorforND 63.2 34.3 316336 739482 332 594
39 Texas R 2015 GregAbbott_TX WendyDavisTexas 59.3 38.9 4707388 26956958 58374 171906

In [9]:
df['odd'] = df['folgov']/df['folch']
ax = df.plot(x='state',y=['odd'],
        title='Ratio of Sitting Governors\' Twitter Follower Counts to that of their Primary Challengers',
        kind='bar', legend=False, figsize=(16,8),logy=True,
        color=df['odd'].apply(lambda x: 'b' if x>1 else 'r'));
plt.rc('xtick', labelsize=18)
plt.text(30,5000,'Red bars denote that the primary challenger\nhas more followers than the sitting governor',fontsize=13);