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
Using apply() method If you need to apply a method over an existing column in order to compute some values that will eventually be added as a new column in the existing DataFrame, then pandas. DataFrame. apply() method should do the trick.
Create a new column by assigning the output to the DataFrame with a new column name in between the [] . Operations are element-wise, no need to loop over rows. Use rename with a dictionary or function to rename row labels or column names.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With