The purpose of this project is to find out the most frequent visitor of the President of The US Barack OBAMA in 2015. We will rely on the data shared by Dataquest availaible here, that present the appointment schedule at the White house at that time.
Our analysis will proceed with different steps as follow:
Let's start our journey by opening the data set and looking at the information available.
from csv import reader
opened_file = open("potus_visitors_2015.csv", encoding = "UTF-8")
#Reading the file
read_file = reader( opened_file )
#Convert the file to a list of lists
potus_visitors = list( read_file )
potus_visitors_header = potus_visitors[0]
potus_visitors = potus_visitors[ 1: ]
#Compute the number of appointment in 2015 with Barack OBAMA
n_appt_2015 = len( potus_visitors[1: ])
#print the header and number of appointments
print( " POTUS visitor information : " )
print( potus_visitors_header )
#Displaying the 5 fives rows
for visitor in potus_visitors[0:4] :
print("\n", visitor,"\n")
print("Number of appointments with the US President in 2015 : ", n_appt_2015 )
POTUS visitor information : ['name', 'appt_made_date', 'appt_start_date', 'appt_end_date', 'visitee_namelast', 'visitee_namefirst', 'meeting_room', 'description'] ['Joshua T. Blanton', '2014-12-18T00:00:00', '1/6/15 9:30', '1/6/15 23:59', '', 'potus', 'west wing', 'JointService Military Honor Guard'] ['Jack T. Gutting', '2014-12-18T00:00:00', '1/6/15 9:30', '1/6/15 23:59', '', 'potus', 'west wing', 'JointService Military Honor Guard'] ['Bradley T. Guiles', '2014-12-18T00:00:00', '1/6/15 9:30', '1/6/15 23:59', '', 'potus', 'west wing', 'JointService Military Honor Guard'] ['Loryn F. Grieb', '2014-12-18T00:00:00', '1/6/15 9:30', '1/6/15 23:59', '', 'potus', 'west wing', 'JointService Military Honor Guard'] Number of appointments with the US President in 2015 : 47953
Above, we can observed that the President is a busy man. About 47953 arrangements in one year. This is equal to 131 meetings/day. For the purpose of our analysis, we will use the name column, the appointment start date column( appt_start_date), and the appointment end date columns( appt_end_date).
Let's continue to exploring the data by calculating each appointment length, and the minimum and the maximum arrangement time values.
To calculate the length of each appointment in our data set, we will subtract the start date in the "appt_end_date" column with the end date in appt_end_date" column. As the dates contain in the five rows above are unclear about the format, we need to avoid dealing with unexpected date format. For instance, we can't declare in confidence that 1/6/15 9:30 in row number 1 was typed in month/day/year format rather than day/month/year. The lack of an "a.m" or "p.m" indicates that the time is likely in 24-hour format.
Luckily, Python provides three standard modules designed to helph working with dates and times. these are:
We will take advantages of the datetime class from the datetime module to deal with data holding dates and times. Below the specific datetime.datetime() class methods we are going to use :
Let's move on by converting all the dates and times in 'appt_start_date' and 'appt_end_date' to the proper format day/month/Year Hour:minute:second.
#Importing the datetime module as alias
import datetime as dt
date_format = "%m/%d/%y %H:%M"
#Looping through potus_visitors data set
for visitor in potus_visitors :
#Assigning the appointment start date to a variable named appt_start_date
appt_start_date = visitor[ 2 ]
appt_end_date = visitor [ 3 ]
#Take advantage of the strptime constructor to convert the variable to a datetime object
appt_start_date = dt.datetime.strptime( appt_start_date, date_format)
appt_end_date = dt.datetime.strptime( appt_end_date, date_format)
#Convert the variables to the format %d/%m/%y %H:%M
visitor[ 2 ] = appt_start_date
visitor[ 3 ] = appt_end_date
print( potus_visitors[ 5397 ] )
['Benjamin D. Kahl', '2015-03-19T13:24:00', datetime.datetime(2015, 3, 24, 9, 30), datetime.datetime(2015, 3, 24, 23, 59), '', 'POTUS', 'west wing drive', 'military honor guard']
So far, each date and time has the same date format in both appt_start_date and appt_end_date columns. We can calculate the length of each appointment.
appt_lengths = []
#Iterating over the potus visitors data set
for visitor in potus_visitors :
#Assigned the name of the visitor in the variable named visitor_name
visitor_name = visitor[0]
#Stored the appointement start date to a variable named appt_start_data
appt_start_date = visitor[ 2 ]
#Stored the appointement end date to a variable named appt_end_data
appt_end_date = visitor[ 3 ]
#Compute the length of each meeting
length = appt_end_date - appt_start_date
#Saved the length of a visitor in a list called appt_length
appt_length = [ visitor_name , appt_start_date, appt_end_date, length ]
#Add the length to the appt_length data set
appt_lengths.append( appt_length )
#print out an example
print("Visitor name | appointment time")
print(appt_lengths[5][0], appt_lengths[5][3])
Visitor name | appointment time Taylor D. Gibbs 14:29:00
In order to discover who spend the latest time at the White House, we need to build first of all a frequency table of appointments length. Then, we will compare the highest frequency with each visitor appointment length. An individual that possesses the largest appointment length is definetely the one who spent the most amount of time at the White House.
To perform this action, we will iterative over the appt_lengths data set, and calculate the frequency of each length. The number of occurence of each data point in the length column will be stored in a frequency dictionary.
#Creating an empty dictionary
appt_freq = {}
#Looping over the appt_lengths list of lists
for row in appt_lengths :
#Assigned the length of each appointment to a variable named length
length = row[ 3 ]
#If the length is not present in appt_dictionary, initiate its frequency to 1
if( length not in appt_freq ) :
appt_freq[ length ] = 1
#Else , increase the length occurence by 1
else :
appt_freq[ length ] +=1
#print the appt_freq table
print( "Appointment duration","|", "Frequency")
for length, freq in appt_freq.items() :
print( length, freq )
#Computing and printing the maximum and minimum time period in an arrangement
max_length = max( appt_freq )
min_length = min( appt_freq )
print(" The lowest amount of time spent in a meeting : ", min_length )
print(" The greatest amount of time spent in a meeting : ", max_length )
Appointment duration | Frequency 14:29:00 1213 13:59:00 1543 13:29:00 696 12:59:00 681 12:29:00 357 11:29:00 1115 14:59:00 511 4:59:00 301 13:04:00 2 11:59:00 1041 10:59:00 1548 10:29:00 5897 9:59:00 996 9:29:00 921 5:59:00 8173 8:29:00 2855 7:59:00 2027 8:59:00 862 13:39:00 12 6:44:00 103 12:14:00 39 11:54:00 6 9:44:00 119 9:04:00 13 11:44:00 32 6:59:00 930 6:39:00 16 6:29:00 457 15:29:00 395 7:29:00 1144 16:59:00 1768 16:29:00 818 15:59:00 460 8:14:00 23 6:14:00 38 5:29:00 985 4:44:00 17 4:29:00 99 3:59:00 185 3:29:00 22 7:44:00 69 8:39:00 36 9:49:00 9 9:14:00 1434 11:04:00 1 10:50:00 1 10:39:00 36 7:04:00 5 13:14:00 347 12:09:00 4 10:44:00 272 6:34:00 24 14:44:00 6 2:29:00 9 6:54:00 6 12:44:00 3 5:44:00 390 16:44:00 40 15:14:00 249 8:44:00 3732 5:39:00 4 5:37:00 1 5:36:00 1 5:26:00 1 5:17:00 1 14:14:00 220 12:39:00 7 7:14:00 224 11:14:00 921 8:54:00 18 8:51:00 1 11:48:00 1 11:37:00 1 11:35:00 1 11:32:00 1 10:11:00 1 10:07:00 1 10:04:00 1 9:56:00 1 9:50:00 1 7:39:00 1 17:59:00 256 16:24:00 1 16:00:00 1 15:53:00 1 15:37:00 1 15:24:00 1 4:56:00 1 8:36:00 1 8:04:00 10 9:09:00 8 10:24:00 4 8:34:00 11 10:09:00 167 10:14:00 344 9:47:00 3 11:09:00 2 11:03:00 1 11:00:00 2 10:54:00 1 10:41:00 1 10:34:00 2 10:19:00 1 10:12:00 1 13:49:00 2 13:44:00 65 13:34:00 13 11:27:00 2 11:19:00 2 11:13:00 2 10:49:00 1 7:19:00 12 2:59:00 11 6:19:00 4 6:09:00 4 6:04:00 1 6:02:00 1 6:00:00 2 5:54:00 1 5:14:00 27 11:39:00 4 7:49:00 176 8:31:00 2 8:24:00 2 8:07:00 1 8:05:00 3 8:01:00 1 7:53:00 1 7:37:00 1 7:24:00 11 12:34:00 1 5:09:00 11 4:14:00 4 3:44:00 1 14:24:00 1 7:34:00 8 9:00:00 1 8:55:00 1 8:52:00 2 8:49:00 5 8:43:00 2 8:40:00 2 8:32:00 3 8:19:00 3 8:10:00 3 8:06:00 1 9:39:00 6 6:24:00 17 9:10:00 1 7:09:00 3 12:17:00 2 6:49:00 7 9:52:00 1 17:29:00 32 5:19:00 6 5:07:00 1 8:42:00 1 4:39:00 1 8:09:00 4 9:41:00 1 8:58:00 16 7:13:00 1 16 days, 12:59:00 102 9:34:00 2 5:55:00 1 5:46:00 1 5:34:00 1 5:31:00 1 5:24:00 2 5:04:00 1 5:02:00 2 9:19:00 6 5:52:00 1 5:33:00 1 5:32:00 1 4:54:00 2 4:49:00 4 4:09:00 1 3:49:00 1 The lowest amount of time spent in a meeting : 2:29:00 The greatest amount of time spent in a meeting : 16 days, 12:59:00
According to the frequency table of appointment length, 102 arrangments has been held during 16 days, 12:59:00 each, which it the greatest amount of time spent in a meeting. On the order hand, only 9 arrangments hung out at the minimum time frame of 2:29:00.
Based on this information, we can search between the 102 appointments the visitor who spend the most amount of time in the White House.
print("Visitor name | appt_start_date | appt_end_date | appt_length")
#Assigning the number of visitor to a variable
n_visitor = 0
#Iterating over the appt_length data set
for row in appt_lengths :
#fetching the name of the visitor
visitor_name = row[ 0 ]
#fetching the start and end date values
appt_start_date = row[ 1 ]
appt_end_date = row[ 2 ]
#fetching his/her appointment length
length = row[ 3 ]
#searching for the visitor with the highest appointment length
if( length == max_length ) :
print (visitor_name," | ",appt_start_date," | ", appt_end_date," | ", length )
#Increase the number of visitor
n_visitor += 1
print(" Number of visitors : ", n_visitor)
Visitor name | appt_start_date | appt_end_date | appt_length Regino B. Madrid | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Glenn A. Dewey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Matthew J. Harding | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Marquez D. Brown | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Mark A. Questad | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Marco A. Lopez | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Marcio G. Botelho | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Tilden E. Olsen | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Oscar Romano | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Glenn C. Paulson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Oscar A. Vanegasgonzalez | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Nicholas A. Hubbard | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Quemaine O. Tolar | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Trevor H. Mowry | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Peter J. Wilson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Robert C. Singer | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Roland K. Felder | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 ShengTsung Wang | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Gregory D. Ridlington | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Michelle A. Rakers | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Michael J. Robinson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 David A. Murray | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Max E. Cripe | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Heather C. Zenobia | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 David J. Young | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Frederick J. VareIII | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Steven L. Owen | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Scott M. Ninmer | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Sarah M. Hart | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Samuel M. Barlow | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Tam T. Tran | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Ryan J. Nowlin | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Ryan H. McGeorge | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Russell A. Wilson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 William J. Back | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Fern E. Sato | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Francis C. Shieh | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 David W. Constantine | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Daniel J. Schenk | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Daniel E. Orban | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Dakota L. Johnson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Courtney M. Morton | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Cody A. Cox | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Clayton T. Bard | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Tessa G. Vinson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Thomas J. MaloyJr | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Ellen M. Dooley | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Eric D. Sabo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Janet C. Bailey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jane A. Cross | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Deborah B. HansonGerber | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Robert S. Delgadillo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Leslye L. Barrett | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Elisabeth A. Plunk | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Caroline E. Stute | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Brian C. Turnmire | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Brigette J. Knox | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Bryan M. Walsh | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Brad R. Weil | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Alexander J. Linnert | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Alan C. Prather | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Aaron D. Clay | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Benjamin J. Andrew | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jennifer L. Mills | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Bernard G. Kolle | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Christopher B. Reaves | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Cameron M. Releford | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Christopher J. McFarlane | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Christopher J. Franke | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Charles J. Paul | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Charlaine L. Prescott | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Chaerim K. Smith | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Carlos H. Arrieta | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Christopher P. Rose | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Christopher E. Schmitt | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Betsy J. Hill | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jennifer A. Paul | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 AnnaMaria R. Mottola | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jesus B. Torres | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jeremiah A. Morrison | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Kyle A. Wyant | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Kurt A. Dupuis | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Kira M. Wharton | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Kelvin M. Contreras | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Karen A. Grimsey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Kara D. Santos | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jason K. Fettig | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jartavious B. Gunter | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jared E. Davidson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Elizabeth A. Matera | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Karen L. Johnson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Dennon L. Audette | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Devin M. Roseberry | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jose E. Arana | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Joseph T. Crisp | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Joseph G. Deluccio | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 John S. Whitt | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Jeffrey M. Strouf | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Juan P. Montoya | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Joseph F. LeBlanc | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Julio C. Tejedamotos | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Joshua D. Figueredo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00 Number of visitors : 102
Unexpectedly, the 102 persons who spent the greatest amount of time in the White House have attended same appointment on the 02 of September 2015 from 11:00am to 23:59 pm. Moreover, the meeting had been held at the State Floo room with the President himself.
As we know who has spent the most amount of time at the White House, let's display the most frequent visitor per month. To do that, we will perform actions as follow:
for row in appt_lengths :
name_1 = row[0]
appt_start_date = row[1]
appt_month = row[2].month