【问题标题】:Python: Get the total hour from start time column and end time column in CSV filePython:从CSV文件中的开始时间列和结束时间列获取总小时数
【发布时间】:2019-10-18 09:50:22
【问题描述】:

我在 CSV 文件中有 2 列“开始”和“结束”。我想用数据作为总小时数写一个列名“Total”。

我的数据:

Start   End 
-----------
16      18  
 3      15  
13      23  
22      15  
 9       1  

我想要的数据:

Start   End     Total
----------------------
16      18       2  
 3      15      12
13      23      10
22      15      17
 9       1      16 

【问题讨论】:

  • 请检查我的解决方案

标签: python database csv dataframe time


【解决方案1】:

使用np.where

dif=(df['End']-df['Start'])
df['Total']=np.where(dif>0,dif,24+dif)
print(df)

   Start  End  Total
0     16   18      2
1      3   15     12
2     13   23     10
3     22   15     17
4      9    1     16

【讨论】:

  • 很高兴为您提供帮助
猜你喜欢
  • 1970-01-01
  • 2012-06-27
  • 2023-01-05
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 2020-05-25
  • 1970-01-01
  • 2019-01-25
相关资源
最近更新 更多