9

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)?

Thank you

Hugo

1 Answer 1

13

You can use numpy's 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
3
  • 4
    I'd recommend checking that atan is really what you want, rather than atan2 (arctan2 in numpy).
    – will
    Jun 24, 2014 at 10:25
  • Good point but arctan2 takes coordinate values, the OP has stated the values are angle values so I think arctan is the more appropriate function here I reckon
    – EdChum
    Jun 24, 2014 at 10:44
  • 1
    atan2 gives an angle though, it's just in a different range (and they do have sin and cos columns). At any rate, worth pointing it out incase it is what they want, and just didn't know about atan2.
    – will
    Jun 24, 2014 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.