Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python/Scipy-Trapz进行积分以找到曲线下的面积(计算电池安培小时数)_Python_Pandas_Numpy_Scipy_Integral - Fatal编程技术网

使用Python/Scipy-Trapz进行积分以找到曲线下的面积(计算电池安培小时数)

使用Python/Scipy-Trapz进行积分以找到曲线下的面积(计算电池安培小时数),python,pandas,numpy,scipy,integral,Python,Pandas,Numpy,Scipy,Integral,我正试图计算一个系统使用的电池使用量,单位为A.h。我用熊猫加载数据,时间指数和电池电流单位为mA。下面的数据框示例: TIME Current 2020-08-07 08:15:54 1.704000 2020-08-07 08:16:04 NaN 2020-08-07 08:16:14 0.852000 2020-08-07 08:16:24 0.852000 2020-08-07 08:16:36 5.96500

我正试图计算一个系统使用的电池使用量,单位为A.h。我用熊猫加载数据,时间指数和电池电流单位为mA。下面的数据框示例:

TIME                    Current
2020-08-07 08:15:54     1.704000
2020-08-07 08:16:04     NaN
2020-08-07 08:16:14     0.852000
2020-08-07 08:16:24     0.852000
2020-08-07 08:16:36     5.965000
                         ...    
2020-08-07 09:14:42    95.446999
2020-08-07 09:14:52    95.446999
2020-08-07 09:15:02    94.595001
2020-08-07 09:15:12    NaN
2020-08-07 09:15:22    98.856003
目前我正在尝试这样做:

from scipy.integrate import trapz
    def battery_usage(df):
        df = df.dropna(subset=['Current']) # remove row from df when 'Current' is NaN
        amphrs = trapz(df['Current'], x=df['Current'].index , axis=0)
        amphrs = ((amphrs*1E-9)/3600)/1000) #Try to convert mA.ns to A.h
        return amphrs

Trapz函数返回一个以纳秒为单位的timedelta64,我不太确定如何处理它。结果实际上似乎是正确的,我假设它知道x轴单位是时间(ns),但不知道序列“current”的单位,因此ns x unitless是ns