[英]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. 在两列中,一列是
datetime
类型,但是另一列是object
类型。 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
OutOfBoundsDatetime:超出范围的纳秒级时间戳: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 使用format参数提供正确的字符串格式,以便to_datetime可以了解将哪种类型的字符串转换为datetime对象
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. 请张贴样本数据以获得正确答案,因为有人已经在评论中写下了答案,这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.