【问题标题】:Prevent pandas from rounding integers when creating dataframe from lists从列表创建数据框时防止熊猫舍入整数
【发布时间】:2021-08-28 13:06:20
【问题描述】:
df1 = pd.DataFrame(listoflists, columns =['size', 'text'])

我将 listoflists 转换为两列 pandas df1

listoflists = [[10.5, 'qqqqq \t\n'], [11.0, 'rrrreee \n'], [10.5, 'rrrrr \n'], [10.000000000000057, 'ertttt \n'], [7.500000000000007, 'ert: ert \n']]

col size 自动四舍五入。我怎样才能防止熊猫这样做?我想保留所有小数。

print(df1)

              size                                               text
0             10.5                                         qqqqq \t\n
1             11.0                                         rrrreee \n
2             10.5                                           rrrrr \n
3             10.0                                          ertttt \n
4             7.5                                         ert: ert \n

我试过了

df1.style.format({
    'size': '{:,.3f}'.format})

但这并没有帮助

【问题讨论】:

    标签: python-3.x pandas dataframe rounding


    【解决方案1】:

    数据存储正确。为了以您喜欢的精度查看它,请在导入 pandas 后使用此命令:

    pd.set_option("display.precision", 15)
    

    根据需要设置精度位数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-14
      • 2020-09-21
      • 2017-05-09
      • 2021-06-08
      • 2017-08-27
      • 2021-09-29
      • 2020-12-20
      相关资源
      最近更新 更多