Skip to content Skip to sidebar Skip to footer

Parse Correct Datetime Using Python And Pandas

So I have two spreadsheets in csv format that I've been provided with for my masters uni course. Part of the processing of the data involved the merging of the files, followed by r

Solution 1:

So I managed to get this figured out, with a little help. Here is the answer

from datetime import datetime

df1 = pd.DataFrame(data_frame, columns=['Title','Author','date_of_loan'])

df1['date_of_loan'] = pd.to_datetime(df1['date_of_loan'], unit='d', origin=pd.Timestamp('1900-01-01'))

df1.sort_values('date_of_loan', ascending=True)

from datetime import datetime

excel_date = 43139
d_time = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + excel_date - 2)
t_time = d_time.timetuple()
print(d_time)
print(t_time)

So how I was able to use that premise in my program was like this

from datetime import datetime

df1 = pd.DataFrame(data_frame, columns=['Title','Author','date_of_loan'])

df1['date_of_loan'] = pd.to_datetime(df1['date_of_loan'], unit='d', origin=pd.Timestamp('1900-01-01'))

df1.sort_values('date_of_loan', ascending=True)

Post a Comment for "Parse Correct Datetime Using Python And Pandas"