pandas中关于DataFrame计算时间差(加减)

Dataframe中的时间是不能直接进行相加减的。如果将两列时间进行加减,会弹出类型错误:

TypeError: unsupported operand type(s) for -: 'str' and 'str'
1
所以需要先用pandas的to_datetime()方法,转化成时间格式进行加减,然后再转换成df格式

new_df = pd.DataFrame(pd.to_datetime(time_df['END_TIME']) - pd.to_datetime(time_df['START_TIME']))

 https://blog.csdn.net/weekdawn/article/details/81391808?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2021-07-11
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案