在 Jupyter/pandas 中显示 2 个小数位,并使用逗号分隔千位?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39166689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 01:53:56  来源:igfitidea点击:

Display 2 decimal places, and use commas to separate thousands, in Jupyter/pandas?

pythonpandasjupyter

提问by Richard

I'm working with pandas 0.18 in Jupyter.

我正在 Jupyter 中使用 pandas 0.18。

I'd like to configure Jupyter/pandas to display 2 decimal places throughout, and to use comma separators in thousands.

我想将 Jupyter/pandas 配置为始终显示 2 个小数位,并以千位为单位使用逗号分隔符。

How can I do this?

我怎样才能做到这一点?

回答by IanS

Configure the following optionin any cell:

在任何单元格中配置以下选项

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

You can also format the output for any float throughout the notebook with this magic command:

您还可以使用以下魔术命令格式化整个笔记本中任何浮点数的输出:

%precision %.2f