I have a dataframe with columns speed and timestamp which is a simple range between 0 and 100. I would like to compute the following integral in a new column distance for each timestamp.
What I did :
import numpy as np
import pandas as pd
#some code ...
dataframe.loc[:, "distance"] = [
np.trapz(
y=dataframe["speed"].iloc[:t],
x=dataframe["timestamp"].iloc[:t],
)
for t in range(0, dataframe.shape[0])
]
However, I do suspect there is more pythonic and efficient way to compute this integral, which better use the power and syntax of pandas, and so on.
Does someone have an idea ?