jupyter notebook中美化pandas中DataFrame的输出

在jupyter notebook中调用pandas时,DataFrame可以被很好的显示,是这个样子的:

jupyter notebook中美化pandas中DataFrame的输出

虽然比idle或者别的终端输出要好看很多,但是具体想查看符合某特定条件的还是需要不能很好的直接显示出来,实际上比较新的版本下,pandas支持一个style 的方法:

1、利用style 和applymap 给特定值显示改变颜色

jupyter notebook中美化pandas中DataFrame的输出

1.1 如果只想对指定列进行颜色改变
jupyter notebook中美化pandas中DataFrame的输出

jupyter notebook中美化pandas中DataFrame的输出

jupyter notebook中美化pandas中DataFrame的输出

2、利用style和apply给特定值改变背景颜色

jupyter notebook中美化pandas中DataFrame的输出

jupyter notebook中美化pandas中DataFrame的输出

3、结合上两种形式

jupyter notebook中美化pandas中DataFrame的输出

4、给百分比显示bar图

jupyter notebook中美化pandas中DataFrame的输出

5、用内置的方法实现2

jupyter notebook中美化pandas中DataFrame的输出

还有更多的样式可以显示,如鼠标悬浮变色,鼠标悬浮突出显示等等,具体见官方介绍:pandas官方介绍