python - TypeError : tan^-1 (tan inverse) 两个数据框列的比率
问题描述
我有两个数据框列“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:无法将系列转换为“浮点”类
解决方案
我相信你需要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
推荐阅读
- javascript - 从对象数组中提取值
- java - 如何从 Android Studio 中的 Java 代码通知中获取 Whatsapp 个人资料照片
- python - 使用 OpenCV 拉直手写文本行
- ngrok - NGROK 不适用于 WAN 或外部本地网络
- c# - 如何列出可以添加到 C# Appium 框架中的设备和 ios,以使其每次测试都使用不同的 Ios 设备和 Ios OS
- reactjs - Redux mapDispatchToProps 方法不起作用
- mysql - Nodejs 续集读取器/写入器异步操作
- asp.net - NuGet 包需要在构建之前恢复。NuGet MSBuild 目标缺失,构建时需要
- python - Peewee 关节不返回所有选定的字段
- r - 在ggplot中,如何在左对齐的同时将文本定位在最右端?