Python Jupyter Notebook打印数据框边框 [英] Python Jupyter Notebook print dataframe borders

查看:437
本文介绍了Python Jupyter Notebook打印数据框边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能有一个简单的问题,但似乎无法在线找到解决方案。
如果我在Jupyter笔记本中创建一个数据框 df,然后使用print()将其打印出来,则在浏览器中显示的表格根本不会显示任何边框。
例如:

 将熊猫作为pd 
导入numpy作为np

df = pd.DataFrame(np.random.rand(5,2),columns = [ a, b])
print(df)

这将显示没有边框的表格。
我阅读了


I'm probably have a simple question but I can't seem to find a solution online. If I create a dataframe "df" in a Jupyter notebook and then I print it out using print(), the table displayed in my broswer does not show any borders at all. For example:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(5,2), columns=["a","b"])
print(df)

This will show a table with no border. I read Jupyter pandas.DataFrame output table format configuration but that seems to help if I simply type

df.head()

not the output of the print() function. Does somebody have any suggestions? Many thanks

解决方案

@Angel, you can add this script in any cell to introduce table borders. Use df instead of print(df)

%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
    border: 1px  black solid !important;
  color: black !important;
}
</style>

这篇关于Python Jupyter Notebook打印数据框边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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