当前位置:   article > 正文

python 打印表格边框_Python Jupyter Notebook打印数据框边框

pandas的表格t添加边框并打印到控制台

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

table.dataframe td, table.dataframe th {

border: 1px black solid !important;

color: black !important;

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/1001110
推荐阅读
相关标签
  

闽ICP备14008679号