I am trying to compute the battery usage in Ah used by a system. I have the data loaded in pandas with a time index and a battery current in mA. Example data frame below:
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
Currently i am trying to do it like this:
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
The Trapz function is returning a timedelta64 in nanoseconds and I'm not too sure what to do with that
结果实际上似乎是正确的,我假设它知道 x 轴单位是时间(ns),但不知道“当前”系列的单位,因此 ns x unitless 是 ns。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.