I had a similar problem and used Yamartino method: https://en.wikipedia.org/wiki/Yamartino_method which is onone pass approximation for wind direction variation. in python it something like (the code is not optimised though):
from math import *
def yamartino(thetalist):
s=0
c=0
n=0.0
for theta in thetalist:
s=s+sin(radians(theta))
c=c+cos(radians(theta))
n+=1
s=s/n
c=c/n
eps=(1-(s**2+c**2))**0.5
sigma=asin(eps)*(1+(2.0/3.0**0.5-1)*eps**3)
return degrees(sigma)