Skip to content
Advertisement

Pandas DataFrame column numerical integration

Currently I have a DataFrame as shown below:

JavaScript

I would like to do the numerical integration of Current with TimeSec (∫Idt) for different Devices and collect the data into a new DataFrame as below:

JavaScript

The problem is that the time interval is not even and the number of data for each device is not even as well.

Advertisement

Answer

Use some numerical integration function, e.g., scipy.integrate.trapz:

JavaScript

Note that this function, using the trapezoid integration rule, allows to specify the x values.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement