Abhilasha Sinha
Abhilasha Sinha

Reputation: 3

Date Comparison in python pandas

I have to compare two columns containing date values and find the difference between the 2 dates.

Out of the 2 columns one is of datetime type however another is an object type. W hen trying to convert the object type to datetime using:

final['Valid to']=pd.to_datetime(final['Valid to'])

I am getting an error:

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9999-12-31 00:00:00

How to convert the column of object type to datetime so that i can compare and get the required result?

Upvotes: 0

Views: 1536

Answers (1)

Ankit Kumar Namdeo
Ankit Kumar Namdeo

Reputation: 1464

use format parameter to provide the correct format of the string so that to_datetime can understand what type of string it is converting into datetime object

in your case it would be like

pd.to_datetime(s, format='%Y-%m-%d %H:%M:%S')

please post the sample data for the correct answer as someone have already written in the comment, that would be helpful.

Upvotes: 1

Related Questions