python - 将带有浮点数列表的 pandas 列转换为带有整数列表的列
问题描述
我有以下带有距离列的熊猫数据框作为浮点数列表。
event type distance
0 5 open [59235.1953125, 34893.48046875, 35969.94921875]
1 3 open [67613.8828125, 49029.328125, 85592.8828125]
2 2 close [2827.9968261719, 1665.8785400391, 1717.271240]
如何将距离列转换为具有整数列表?
event type distance
0 5 open [59235, 34893, 359670]
1 3 open [67614, 49029, 85593]
2 2 close [2828, 1666, 1717]
解决方案
只是一个循环/应用:
df['distance'] = [[round(y) for y in x] for x in df['distance']]
推荐阅读
- json - FTL eval_json 失败
- c++ - C++11,在成员函数中使用 printf("%p", *this) 会调用析构函数,为什么?
- python - 为什么 doxygen 不显示带注释的公共属性?
- javascript - 渲染过程中未定义的上下文桥中的 API
- python - Repl.it 环境秘密变量是 None 类型
- java - 为什么我需要添加双引号来打印java中char数组的第一个和最后一个元素
- javascript - 如何创建一次 p 元素函数并在每个函数中使用它以在屏幕上打印
- amazon-web-services - 用于多个项目的 Terraform 和 Gitlab CI 管道
- java - 在 Java 中复制 OPENSSL dgst 命令
- java - 如何创建一个 flink https 请求