首页 > 解决方案 > 将带有浮点数列表的 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]

标签: pythonpandaslist

解决方案


只是一个循环/应用:

df['distance'] = [[round(y) for y in x] for x in df['distance']]

推荐阅读