在 pandas 中格式化数字 [英] formatting numbers in pandas

查看:81
本文介绍了在 pandas 中格式化数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于pandas.DataFrame:df

for a pandas.DataFrame: df

     min           max          mean
a    0.0  2.300000e+04  6.450098e+02
b    0.0  1.370000e+05  1.651754e+03
c  218.0  1.221550e+10  3.975262e+07
d    1.0  5.060000e+03  2.727708e+02
e    0.0  6.400000e+05  6.560047e+03

我想格式化显示,例如在":,.2f" 格式(即##,###.##)并删除指数.

I would like to format the display such as numbers show in the ":,.2f" format (that is ##,###.##) and remove the exponents.

我试过:df.style.format("{:,.2f}")它给出: 我不知道该怎么办.请问有线索吗?

I tried: df.style.format("{:,.2f}")which gives: <pandas.io.formats.style.Styler object at 0x108b86f60> that i have no idea what to do with. Any lead please?

推荐答案

试试这个年轻的 Pandas 学徒

try this young Pandas apprentice

pd.options.display.float_format = '{:,.2f}'.format

这篇关于在 pandas 中格式化数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆