I have a time-idexed data that must be resampled:
interval = pd.Timedelta(1/8, "s")
resampled_df = df[["T", "N"]].resample(interval).max()
it works very fast, but I need custom aggregation function (extreme) instead of max
def extreme_agg(array_like):
# return max or min - which absolute value is greater
return max(array_like.max(), array_like.min(), key=abs)
interval = pd.Timedelta(1/8, "s")
resampled_df = df[["T", "N"]].resample(interval).apply(extreme_agg)
I tried also
resampled_df = df[["T", "N"]].resample(interval).agg(extreme_agg)
But both ways are terribly slow. Do you have any idea how to make it faster?
Or is there a fast equivalent of my extreme_agg?