我有这样一个数据帧
datecol1 datecol2
2005-02-22 EmployeeNotFound
2010-02-21 2010-02-22
EmployeeNotFound EmployeeNotFound
EmployeeNotFound 2010-02-22
两列的数据类型都是Object
我想比较这两列并得到每列的最大日期
所以预期的结果是
datecol1 datecol2 ExpectedResult
2005-02-22 EmployeeNotFound 2005-02-22
2010-02-21 2010-02-22 2010-02-22
EmployeeNotFound EmployeeNotFound EmployeeNotFound
EmployeeNotFound 2010-02-25 2010-02-25
ExpectedResult的数据类型将再次成为对象
将列转换为日期时间,按轴1获取
max
,最后转换为字符串并替换NaT
:也可以使用numpy,因为numpy函数更快
这里首先将填充
datecol1
的所有有效值,然后剩余的值将由第二列datecol2
填充相关问题 更多 >
编程相关推荐