python - Calculate the tangent of an angle for multiple angles in a pandas dataframe -


i have following dataframe:

    date        time                  b 0   2016-01-01  00:00:00.000    443.30  469.80 1   2016-01-01  00:01:00.000    145.80  470.00 2   2016-01-01  00:03:00.000    452.20  471.00 3   2016-01-01  00:04:00.000    174.20  461.30 4   2016-01-01  00:05:00.000    345.30  471.90 

i'm trying calculate tangent of angles (a/b) rows of dataframe.

my code:

import numpy np import math m  df['i']=np.(m.degrees(m.atan(df['a']/df['b']))) 

the error produced:

file "<ipython-input-70-0abce3902356>", line 3 df['i']=np.(m.degrees(m.atan(df['a']/df['b'])))            ^ syntaxerror: invalid syntax 

taking () out produces error:

df['i']=np.m.degrees(m.atan(df['a']/df['b']))  attributeerror                            traceback (most recent call last) <ipython-input-71-7cfc6387d664> in <module>()        1         2   ----> 3 df['i']=np.m.degrees(m.atan(df['a']/df['b']))  attributeerror: module 'numpy' has no attribute 'm' 

i understand errors telling me, don't know how go performing calculation. appreciated!

just use numpy functions np.degrees , np.arctan. math module functions aren't designed work on vectors.

df['i'] = np.degrees(np.arctan(df['a']/df['b'])) df          date          time           b          0  2016-01-01  00:00:00.000  443.3  469.8  43.337628 1  2016-01-01  00:01:00.000  145.8  470.0  17.234557 2  2016-01-01  00:03:00.000  452.2  471.0  43.833393 3  2016-01-01  00:04:00.000  174.2  461.3  20.687963 4  2016-01-01  00:05:00.000  345.3  471.9  36.193786 

by way, np – alias numpy , m – alias math (builtin). not sure why you're trying use them way are.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -