TypeError:两个数据框列之比的tan ^ -1(tan逆)

时间:2019-05-15 05:24:45

标签: python pandas math

我有两个数据框列“ vibration_X”和“ vibration_Y”。在某些列中,我几乎没有零值。我想创建新的列“ theta”,它是振动_Y和振动_X的tan倒数的比率。

以下是我的示例数据:

     vibration_Y  vibration_X
0           10            7
1           10            8
2            9            8
3           10           11
4           13            5
5            3            0
6           12            8
7           12            9
8           11           10
9           10           11

下面是我尝试过的并且遇到错误的代码:

df['theta'] = math.atan(df['vibration_Y']/df['vibration_X'].astype(float))
  

TypeError:无法将系列转换为类“ float”

1 个答案:

答案 0 :(得分:2)

我相信您需要numpy.arctan

df['theta'] = np.arctan(df['vibration_Y']/df['vibration_X'])
print (df)
   vibration_Y  vibration_X     theta
0           10            7  0.960070
1           10            8  0.896055
2            9            8  0.844154
3           10           11  0.737815
4           13            5  1.203622
5            3            0  1.570796
6           12            8  0.982794
7           12            9  0.927295
8           11           10  0.832981
9           10           11  0.737815
相关问题