Friday, 15 July 2011

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



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

i have dataframe next columns (sin , cos of 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 create new column arctan of angle (atan(sin/cos)?

thank you

hugo

you can utilize 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

python pandas

No comments:

Post a Comment