简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM