python-3.x - 从列表创建数据框时防止熊猫舍入整数
问题描述
df1 = pd.DataFrame(listoflists, columns =['size', 'text'])
我将 a 转换listoflists
为两列 pandasdf1
listoflists = [[10.5, 'qqqqq \t\n'], [11.0, 'rrrreee \n'], [10.5, 'rrrrr \n'], [10.000000000000057, 'ertttt \n'], [7.500000000000007, 'ert: ert \n']]
colsize
会自动舍入。我怎样才能防止熊猫这样做?我想保留所有小数。
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})
但这并没有帮助
解决方案
数据存储正确。为了以您喜欢的精度查看它,请在导入 pandas 后使用此命令:
pd.set_option("display.precision", 15)
将精度位数设置为您需要的数量。
推荐阅读
- c++ - 为什么迭代器调试在调试版本中会减慢 std::unordered_map 200x?
- c# - 在 UWP desktop-bridge 包中发送语音识别 args.Result 作为参数
- class - 确保数据成员的内存位置在基类之前
- android - Butterknife 在动态功能子项目中不起作用:错误:包 R2 不存在
- mysql - 如何在 MySQL 中获取分组计数变量的最大值
- typescript - 如何从 Firebase 文档中过滤数据?
- javascript - 多个动态创建的 quill 编辑器可以使用同一个工具栏吗
- java - 使用非当前 Java 版本
- vba - 访问 vba IE getElementById“需要对象”错误 424
- pointers - 在(免费)Pascal 中,函数可以返回一个可以在不取消引用的情况下修改的值吗?