from simulation data with variable timestep I have a irregular time-vector as index for my values, they are stored in a pandas.DataFrame.
Let's consider a simplified test case:
import pandas as pd
import datetime
time_vec = [datetime.time(0,0),datetime.time(0,0),datetime.time(0,5),datetime.time(0,7),datetime.time(0,10)]
df = pd.DataFrame([1,2,4,3,6],index = time_vec)
Using the normal df.mean()
-function would result in the answer 3.2, which would only be true if the time-vector would be equidistant.
I think the correct result would be 3.55 as for the first timestep (zero seconds long), the average value is 1.5, for the second timestep the average Value is 3 (five minutes long) etc, this results in:
1.5 * 0 + 3*5 + 3.5 * 2 + 4.5 * 3 = 35.5
which results in an average of 3.55 (35.5 / (0 + 5 + 2 + 3)).
Is there an efficient way to do this with pandas?
This should finally result in something like
df.resample('15M',how = 'This very Method I am looking for')
to create average values with an equidistant time-vector.