I have a Pandas DataFrame which has two columns containing some angles in the range [-pi, pi). I need to calculate the instantaneous angular velocity on each row, which I can do using diff(), however this naive approach fails when my data crosses the discontinuity from pi to -pi, e.g.
I'm trying to use numpy.unwrap() on my columns but when I try the code below I get a ValueError.
angle_data["theta"].apply(np.unwrap)
<Traceback message>
ValueError: diff requires input that is at least one dimensional
This also occurs if I copy the columns to a Pandas Series and try to use apply(np.unwrap)
.
I can workaround this by doing
angle_data["theta"] = pd.Series(np.unwrap(angle_data["theta"]))
or by using apply on multiple columns at once, but I'd like to know why the apply(np.unwrap)
method doesn't work for a Pandas Series.