Add high level LINE BY LINE comments of whats takingplace in the program.
LINE BY LINE. A comment for every lineplease.
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import matplotlib.pyplot as plt
import pandas as pd
#Converting CSV file to DataFrames by reading them
jobs_df = pd.read_csv(‘Jobs.csv’, sep=’t’)
presidents_df = pd.read_csv(‘Presidents.csv’, sep=’t’)
#Transforming date string to date object in each of thedataframes
jobs_df[‘Month’] = pd.to_datetime(jobs_df[‘Month’])
presidents_df[‘Took_office’] =pd.to_datetime(presidents_df[‘Took_office’])
presidents_df[‘Left_office’] =pd.to_datetime(presidents_df[‘Left_office’])
presidents = presidents_df.sort_values(‘Took_office’)
jobs_df.head()
presidents.head()
#Calculating the number of jobs in their first 2 years
def calculate_jobs(president):
took_office = president.Took_office
left_office = president.Left_office
effective_date_start = took_office + relativedelta(months =1)
effective_date_start = effective_date_start.replace(day = 1)
#If the term is less then 2 years
effective_end_date = effective_date_start + relativedelta(years =2)
effective_end_date = left_office if left_office