"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

February 11, 2019

Day # 209 Pandas DateTime Coding Snippets

Lessons working on Pandas DateTime columns

import numpy as np
from dateutil.parser import parse
a = parse('2012-11-01 02:48:30')
print(a)
import time
print(int(time.mktime(a.timetuple())))
import pandas as pd
data = [['Alex','2012-11-01 02:48:30'],['Bob','2011-11-01 02:48:30'],['Clarke','2013-11-01 02:48:30']]
#Create a dataframe
df = pd.DataFrame(data,columns=['Name','EmploymentDate'])
#convert str to date time
df['Date_time1'] = pd.to_datetime(df['EmploymentDate'])
#convert date time to int value
df['date_time_int'] = df.Date_time1.astype(np.int64)
print(df)


Happy Mastering DL!!!

No comments: