Forgive me as I'm new to pandas, but I'm trying to resample an array of wind direction measurements by a custom function to do the vector mean:
def windavg(direction):
rads = (direction*np.pi)/180
s = np.arctan2(np.sum(np.sin(rads)),np.sum(np.cos(rads)))
mean_direction = ((s*180)/np.pi + 360) % 360
return mean_direction
My dataframe winddir
looks like this:
and I've been trying to resample it using:
resample_met = winddir.resample('1H',on='date').apply(windavg)
but I keep getting the error TypeError: cannot perform __mul__ with this index type: DatetimeArray
, which is tripping on the first line of the function. I'm confused as to why the resample is trying to perform the function on the dates, as from what I understand from this question I can just use my custom function as a substitute for the standard methods of resampling like .mean()
or .sum()
.
What am I misinterpreting about how this function works, and how can I apply this custom function to the resampling process?