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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM