我有pandas对象,列类型是float
df = pd.DataFrame([1.12 , 37.95])
但是当我将列更改为元组/列表时,该数字具有更多的数字小写点,我该如何解决?
print(tuple(df[0]))
(1.1200000000000001, 37.950000000000003)
答案 0 :(得分:0)
对我来说,首先转换为list
,然后转换为tuple
:
print(df[0].tolist())
[1.12, 37.95]
print(tuple(df[0].tolist()))
(1.12, 37.95)