{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Nano Project : POTUS VISITORS\n", "\n", "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][1] availaible [here][2], that present the appointment schedule at the White house at that time.\n", "\n", "[1]: https://www.dataquest.io/\n", "[2]: https://app.dataquest.io/m/353/working-with-dates-and-times-in-python/4/the-datetime-class\n", "\n", "Our analysis will proceed with different steps as follow:\n", "\n", "* Firstly, we compute each appointment length, the minimum and maximum appointment time values.\n", "* Then we figure out who spent the most amount of time at the white House.\n", "* Finally, we find out who visited the White House the most each month.\n", "\n", "## 1. Exploring the \"potus_visitors_2015.csv\" data set.\n", "\n", "Let's start our journey by opening the data set and looking at the information available.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " POTUS visitor information : \n", "['name', 'appt_made_date', 'appt_start_date', 'appt_end_date', 'visitee_namelast', 'visitee_namefirst', 'meeting_room', 'description']\n", "\n", " ['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'] \n", "\n", "\n", " ['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'] \n", "\n", "\n", " ['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'] \n", "\n", "\n", " ['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'] \n", "\n", "Number of appointments with the US President in 2015 : 47953\n" ] } ], "source": [ "from csv import reader\n", "opened_file = open(\"potus_visitors_2015.csv\", encoding = \"UTF-8\")\n", "#Reading the file\n", "read_file = reader( opened_file )\n", "#Convert the file to a list of lists\n", "potus_visitors = list( read_file )\n", "\n", "potus_visitors_header = potus_visitors[0]\n", "potus_visitors = potus_visitors[ 1: ]\n", "\n", "#Compute the number of appointment in 2015 with Barack OBAMA\n", "n_appt_2015 = len( potus_visitors[1: ])\n", "#print the header and number of appointments\n", "print( \" POTUS visitor information : \" )\n", "print( potus_visitors_header )\n", "\n", "#Displaying the 5 fives rows\n", "for visitor in potus_visitors[0:4] :\n", " print(\"\\n\", visitor,\"\\n\")\n", " \n", "print(\"Number of appointments with the US President in 2015 : \", n_appt_2015 )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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*).\n", "\n", "Let's continue to exploring the data by calculating each appointment length, and the minimum and the maximum arrangement time values.\n", "\n", "## 2. Computing the appointment lengths.\n", "\n", "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.\n", "\n", "Luckily, Python provides three standard modules designed to helph working with dates and times. these are:\n", "\n", "* The Calender module\n", "* The time module\n", "* The datetime module\n", "\n", "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 :\n", "* **datetime.strptime()** : This constructor returns a datetime object defined using a special syntax system to describe date and times formats.\n", "\n", "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*." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['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']\n" ] } ], "source": [ "#Importing the datetime module as alias\n", "import datetime as dt\n", "date_format = \"%m/%d/%y %H:%M\"\n", "#Looping through potus_visitors data set\n", "for visitor in potus_visitors :\n", " #Assigning the appointment start date to a variable named appt_start_date\n", " appt_start_date = visitor[ 2 ] \n", " appt_end_date = visitor [ 3 ]\n", " #Take advantage of the strptime constructor to convert the variable to a datetime object\n", " appt_start_date = dt.datetime.strptime( appt_start_date, date_format)\n", " appt_end_date = dt.datetime.strptime( appt_end_date, date_format)\n", " #Convert the variables to the format %d/%m/%y %H:%M\n", " visitor[ 2 ] = appt_start_date\n", " visitor[ 3 ] = appt_end_date\n", " \n", "print( potus_visitors[ 5397 ] )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Visitor name | appointment time\n", "Taylor D. Gibbs 14:29:00\n" ] } ], "source": [ "appt_lengths = []\n", "#Iterating over the potus visitors data set\n", "for visitor in potus_visitors :\n", " #Assigned the name of the visitor in the variable named visitor_name\n", " visitor_name = visitor[0]\n", " #Stored the appointement start date to a variable named appt_start_data\n", " appt_start_date = visitor[ 2 ]\n", " #Stored the appointement end date to a variable named appt_end_data\n", " appt_end_date = visitor[ 3 ]\n", " #Compute the length of each meeting\n", " length = appt_end_date - appt_start_date\n", " #Saved the length of a visitor in a list called appt_length\n", " appt_length = [ visitor_name , appt_start_date, appt_end_date, length ]\n", " #Add the length to the appt_length data set\n", " appt_lengths.append( appt_length )\n", "#print out an example\n", "print(\"Visitor name | appointment time\")\n", "print(appt_lengths[5][0], appt_lengths[5][3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " \n", "## 3. Figuring out the visitor who spent the most amount of time at the White House\n", "\n", "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.\n", "\n", "### 3.1 Building the frequency table of appointments length.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Appointment duration | Frequency\n", "14:29:00 1213\n", "13:59:00 1543\n", "13:29:00 696\n", "12:59:00 681\n", "12:29:00 357\n", "11:29:00 1115\n", "14:59:00 511\n", "4:59:00 301\n", "13:04:00 2\n", "11:59:00 1041\n", "10:59:00 1548\n", "10:29:00 5897\n", "9:59:00 996\n", "9:29:00 921\n", "5:59:00 8173\n", "8:29:00 2855\n", "7:59:00 2027\n", "8:59:00 862\n", "13:39:00 12\n", "6:44:00 103\n", "12:14:00 39\n", "11:54:00 6\n", "9:44:00 119\n", "9:04:00 13\n", "11:44:00 32\n", "6:59:00 930\n", "6:39:00 16\n", "6:29:00 457\n", "15:29:00 395\n", "7:29:00 1144\n", "16:59:00 1768\n", "16:29:00 818\n", "15:59:00 460\n", "8:14:00 23\n", "6:14:00 38\n", "5:29:00 985\n", "4:44:00 17\n", "4:29:00 99\n", "3:59:00 185\n", "3:29:00 22\n", "7:44:00 69\n", "8:39:00 36\n", "9:49:00 9\n", "9:14:00 1434\n", "11:04:00 1\n", "10:50:00 1\n", "10:39:00 36\n", "7:04:00 5\n", "13:14:00 347\n", "12:09:00 4\n", "10:44:00 272\n", "6:34:00 24\n", "14:44:00 6\n", "2:29:00 9\n", "6:54:00 6\n", "12:44:00 3\n", "5:44:00 390\n", "16:44:00 40\n", "15:14:00 249\n", "8:44:00 3732\n", "5:39:00 4\n", "5:37:00 1\n", "5:36:00 1\n", "5:26:00 1\n", "5:17:00 1\n", "14:14:00 220\n", "12:39:00 7\n", "7:14:00 224\n", "11:14:00 921\n", "8:54:00 18\n", "8:51:00 1\n", "11:48:00 1\n", "11:37:00 1\n", "11:35:00 1\n", "11:32:00 1\n", "10:11:00 1\n", "10:07:00 1\n", "10:04:00 1\n", "9:56:00 1\n", "9:50:00 1\n", "7:39:00 1\n", "17:59:00 256\n", "16:24:00 1\n", "16:00:00 1\n", "15:53:00 1\n", "15:37:00 1\n", "15:24:00 1\n", "4:56:00 1\n", "8:36:00 1\n", "8:04:00 10\n", "9:09:00 8\n", "10:24:00 4\n", "8:34:00 11\n", "10:09:00 167\n", "10:14:00 344\n", "9:47:00 3\n", "11:09:00 2\n", "11:03:00 1\n", "11:00:00 2\n", "10:54:00 1\n", "10:41:00 1\n", "10:34:00 2\n", "10:19:00 1\n", "10:12:00 1\n", "13:49:00 2\n", "13:44:00 65\n", "13:34:00 13\n", "11:27:00 2\n", "11:19:00 2\n", "11:13:00 2\n", "10:49:00 1\n", "7:19:00 12\n", "2:59:00 11\n", "6:19:00 4\n", "6:09:00 4\n", "6:04:00 1\n", "6:02:00 1\n", "6:00:00 2\n", "5:54:00 1\n", "5:14:00 27\n", "11:39:00 4\n", "7:49:00 176\n", "8:31:00 2\n", "8:24:00 2\n", "8:07:00 1\n", "8:05:00 3\n", "8:01:00 1\n", "7:53:00 1\n", "7:37:00 1\n", "7:24:00 11\n", "12:34:00 1\n", "5:09:00 11\n", "4:14:00 4\n", "3:44:00 1\n", "14:24:00 1\n", "7:34:00 8\n", "9:00:00 1\n", "8:55:00 1\n", "8:52:00 2\n", "8:49:00 5\n", "8:43:00 2\n", "8:40:00 2\n", "8:32:00 3\n", "8:19:00 3\n", "8:10:00 3\n", "8:06:00 1\n", "9:39:00 6\n", "6:24:00 17\n", "9:10:00 1\n", "7:09:00 3\n", "12:17:00 2\n", "6:49:00 7\n", "9:52:00 1\n", "17:29:00 32\n", "5:19:00 6\n", "5:07:00 1\n", "8:42:00 1\n", "4:39:00 1\n", "8:09:00 4\n", "9:41:00 1\n", "8:58:00 16\n", "7:13:00 1\n", "16 days, 12:59:00 102\n", "9:34:00 2\n", "5:55:00 1\n", "5:46:00 1\n", "5:34:00 1\n", "5:31:00 1\n", "5:24:00 2\n", "5:04:00 1\n", "5:02:00 2\n", "9:19:00 6\n", "5:52:00 1\n", "5:33:00 1\n", "5:32:00 1\n", "4:54:00 2\n", "4:49:00 4\n", "4:09:00 1\n", "3:49:00 1\n", " The lowest amount of time spent in a meeting : 2:29:00\n", " The greatest amount of time spent in a meeting : 16 days, 12:59:00\n" ] } ], "source": [ "#Creating an empty dictionary\n", "appt_freq = {}\n", "\n", "#Looping over the appt_lengths list of lists\n", "for row in appt_lengths :\n", " #Assigned the length of each appointment to a variable named length\n", " length = row[ 3 ]\n", " #If the length is not present in appt_dictionary, initiate its frequency to 1\n", " if( length not in appt_freq ) :\n", " appt_freq[ length ] = 1\n", " \n", " #Else , increase the length occurence by 1\n", " else :\n", " appt_freq[ length ] +=1\n", " \n", "#print the appt_freq table\n", "print( \"Appointment duration\",\"|\", \"Frequency\")\n", "for length, freq in appt_freq.items() :\n", " print( length, freq )\n", "#Computing and printing the maximum and minimum time period in an arrangement\n", "max_length = max( appt_freq )\n", "min_length = min( appt_freq )\n", "print(\" The lowest amount of time spent in a meeting : \", min_length )\n", "print(\" The greatest amount of time spent in a meeting : \", max_length )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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**.\n", "\n", "### 3.2 Finding the visitor who spent the most amount of time at the White House in 2015\n", "\n", "Based on this information, we can search between the 102 appointments the visitor who spend the most amount of time in the White House." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Visitor name | appt_start_date | appt_end_date | appt_length\n", "Regino B. Madrid | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Glenn A. Dewey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Matthew J. Harding | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Marquez D. Brown | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Mark A. Questad | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Marco A. Lopez | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Marcio G. Botelho | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Tilden E. Olsen | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Oscar Romano | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Glenn C. Paulson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Oscar A. Vanegasgonzalez | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Nicholas A. Hubbard | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Quemaine O. Tolar | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Trevor H. Mowry | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Peter J. Wilson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Robert C. Singer | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Roland K. Felder | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "ShengTsung Wang | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Gregory D. Ridlington | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Michelle A. Rakers | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Michael J. Robinson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "David A. Murray | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Max E. Cripe | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Heather C. Zenobia | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "David J. Young | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Frederick J. VareIII | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Steven L. Owen | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Scott M. Ninmer | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Sarah M. Hart | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Samuel M. Barlow | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Tam T. Tran | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Ryan J. Nowlin | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Ryan H. McGeorge | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Russell A. Wilson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "William J. Back | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Fern E. Sato | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Francis C. Shieh | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "David W. Constantine | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Daniel J. Schenk | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Daniel E. Orban | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Dakota L. Johnson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Courtney M. Morton | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Cody A. Cox | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Clayton T. Bard | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Tessa G. Vinson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Thomas J. MaloyJr | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Ellen M. Dooley | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Eric D. Sabo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Janet C. Bailey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jane A. Cross | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Deborah B. HansonGerber | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Robert S. Delgadillo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Leslye L. Barrett | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Elisabeth A. Plunk | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Caroline E. Stute | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Brian C. Turnmire | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Brigette J. Knox | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Bryan M. Walsh | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Brad R. Weil | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Alexander J. Linnert | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Alan C. Prather | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Aaron D. Clay | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Benjamin J. Andrew | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jennifer L. Mills | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Bernard G. Kolle | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Christopher B. Reaves | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Cameron M. Releford | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Christopher J. McFarlane | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Christopher J. Franke | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Charles J. Paul | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Charlaine L. Prescott | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Chaerim K. Smith | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Carlos H. Arrieta | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Christopher P. Rose | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Christopher E. Schmitt | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Betsy J. Hill | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jennifer A. Paul | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "AnnaMaria R. Mottola | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jesus B. Torres | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jeremiah A. Morrison | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Kyle A. Wyant | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Kurt A. Dupuis | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Kira M. Wharton | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Kelvin M. Contreras | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Karen A. Grimsey | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Kara D. Santos | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jason K. Fettig | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jartavious B. Gunter | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jared E. Davidson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Elizabeth A. Matera | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Karen L. Johnson | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Dennon L. Audette | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Devin M. Roseberry | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jose E. Arana | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Joseph T. Crisp | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Joseph G. Deluccio | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "John S. Whitt | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Jeffrey M. Strouf | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Juan P. Montoya | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Joseph F. LeBlanc | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Julio C. Tejedamotos | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", "Joshua D. Figueredo | 2015-12-02 11:00:00 | 2015-12-18 23:59:00 | 16 days, 12:59:00\n", " Number of visitors : 102\n" ] } ], "source": [ "print(\"Visitor name | appt_start_date | appt_end_date | appt_length\")\n", "#Assigning the number of visitor to a variable\n", "n_visitor = 0\n", "#Iterating over the appt_length data set\n", "for row in appt_lengths :\n", " #fetching the name of the visitor\n", " visitor_name = row[ 0 ]\n", " #fetching the start and end date values\n", " appt_start_date = row[ 1 ]\n", " appt_end_date = row[ 2 ]\n", " #fetching his/her appointment length\n", " length = row[ 3 ]\n", " #searching for the visitor with the highest appointment length\n", " \n", " if( length == max_length ) :\n", " print (visitor_name,\" | \",appt_start_date,\" | \", appt_end_date,\" | \", length )\n", " #Increase the number of visitor\n", " n_visitor += 1\n", " \n", "print(\" Number of visitors : \", n_visitor)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "### 3.3 Figuring out the most frequent visitor per month\n", "\n", "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:\n", "\n", "* Firstly, we will a frequency table of the name of a visitor to count the occurences of his/her presence at the White House in 2015\n", "* For each visitor, we'll compute his/her appointment length from each month.\n", "* Then, we'll choose the visitor with the greatest appointment length in each month. " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "for row in appt_lengths :\n", " name_1 = row[0]\n", " appt_start_date = row[1]\n", " appt_month = row[2].month\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }