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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24383351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:11:39  来源:igfitidea点击:

How do I calculate a new column in Pandas based a on trignometric function?

pythonpandas

提问by Hugo

I have a dataframe with the following columns (sin and cos of a angle)

我有一个包含以下列的数据框(角度的正弦和余弦)

                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

How can I create a new column with the arctan of the angle (atan(sin/cos)?

如何使用角度的反正切(atan(sin/cos))创建一个新列?

Thank you

谢谢

Hugo

雨果

回答by EdChum

You can use numpy's arctan

你可以使用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