如何基于三角函数计算Pandas中的新列?

Hug*_*ugo 5 python pandas

我有一个包含以下列的数据帧(sin和cos角度)

                SWD         CWD
2013-12-06  -0.394097   -0.350099
2013-12-07  -0.388295   -0.271105
2013-12-08  -0.391894   -0.202537
2013-12-09  -0.388662   -0.430063
2013-12-10  -0.396427   -0.433933
Run Code Online (Sandbox Code Playgroud)

如何使用角度的arc​​tan创建一个新列(atan(sin/cos)?

谢谢

雨果

EdC*_*ica 7

你可以使用numpy的 arctan

In [42]:

df['ATAN'] = np.arctan(df['SWD']/df['CWD'])
df
Out[42]:
         Date       SWD       CWD      ATAN
0  2013-12-06 -0.394097 -0.350099  0.844451
1  2013-12-07 -0.388295 -0.271105  0.961284
2  2013-12-08 -0.391894 -0.202537  1.093787
3  2013-12-09 -0.388662 -0.430063  0.734874
4  2013-12-10 -0.396427 -0.433933  0.740260
Run Code Online (Sandbox Code Playgroud)

  • 我建议检查atan是否真的是你想要的,而不是[atan2](http://en.wikipedia.org/wiki/Atan2)([`arctan2`](http://docs.scipy.org/在numpy中的doc/numpy/reference/generated/numpy.arctan2.html). (2认同)