从列表创建数据框时防止 pandas 舍入整数
Prevent pandas from rounding integers when creating dataframe from lists
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
自动四舍五入。我怎样才能防止 pandas 这样做?我想保留所有小数。
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)
根据需要设置精度位数。
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
自动四舍五入。我怎样才能防止 pandas 这样做?我想保留所有小数。
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)
根据需要设置精度位数。