【问题标题】:Python Pandas Dataframe convert String column to Float while Keeping Precision (decimal places)Python Pandas Dataframe 将字符串列转换为浮点数,同时保持精度(小数位)
【发布时间】:2022-01-20 07:52:08
【问题描述】:

当我将一列从字符串转换为浮点数时,我会丢失小数位,有没有明确的方法如何保留小数位?

dicti = {'1': ['55.230530663425',
  '43.597357785755'],
 '2': ['25.231784186637',
  '93.59759890623'],
 '3': ['75.229467797447',
  '33.597732846763'],
 '4': ['15.228959922301',
  '33.596897400263'],
 '5': ['95.231278845519',
  '23.599502230125']}


df = pd.DataFrame.from_dict(dicti, 'index')
df[0] = df[0].astype(float)
df[1] = df[1].astype(float)
print(df)

           0          1
1  55.230531  43.597358
2  25.231784  93.597599
3  75.229468  33.597733
4  15.228960  33.596897
5  95.231279  23.599502

【问题讨论】:

  • 它们被保留,只是没有打印出来

标签: python pandas dataframe


【解决方案1】:

查看来自

的最佳答案

Pandas data precision

如果您想查看更多小数位,请查看如何更改显示精度。如前所述,存储了完整的精度,只是不显示。

【讨论】:

    猜你喜欢
    • 2015-05-25
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2019-11-15
    • 2021-07-22
    • 1970-01-01
    相关资源
    最近更新 更多