【问题标题】:Extracting the minute difference between two datetime values pandas dataframe提取两个日期时间值熊猫数据框之间的微小差异
【发布时间】:2020-08-05 09:19:26
【问题描述】:

我想要一列以分钟为单位记录两次之间的差异......

>

 analysis['Duration in Minutes']=((analysis['DischEndTime'])-(analysis['DischStTime'])) 
> analysis['Duration in Minutes']=(analysis['Duration in Minutes']) / np.timedelta64(1, 'm')
>>>>>>>0.761111
>(analysis['Duration in Minutes']).round(1)
>>>>>>>0.8 

我希望输出为 0.7 而不是 0.8,而不是使用将值四舍五入到下一位的 round 函数

【问题讨论】:

    标签: python pandas dataframe dt minute


    【解决方案1】:

    你可以编写一个自定义函数来使用round函数实现ceil函数。像这样的东西:

    In [137]: def my_floor(a, precision=0):
         ...:     return np.round(a - 0.5 * 10**(-precision), precision)
         ...:
    
    In [138]: my_floor(0.786456,1)
    Out[138]: 0.7
    

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 2018-02-23
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 2017-09-07
      • 2022-10-02
      • 1970-01-01
      相关资源
      最近更新 更多