user15964 :
For example, define
df=pd.DataFrame(np.random.randint(0,10,(6,6)))
df
Which gives below display in Jupyter notebook
My question is that is it possible to add a column delimiter to the dataframe like
Thank you for all the answers, currently I use below custom functions
def css_border(x,pos):
return ["border-left: 1px solid red" if i in pos else "border: 0px" for i, col in enumerate(x)]
def display_df_with_delimiter(df,pos):
return df.style.apply(partial(css_border,pos=pos), axis=1)
and
display_df_with_delimiter(df,[0,1,2,5])
gives
Matus Dubrava :
This piece of code should add the desired lines to the table.
from IPython.display import display, HTML
CSS = """
.rendered_html td:nth-child(even) {
border-left: 1px solid red;
}
"""
HTML('<style>{}</style>'.format(CSS))
Note that you can change the style of those linse by simply changing the definition of border-left
attribute, i.e border-left: 2px solid green
to make the lines thicker and green.
Here is a snapshot demonstrating the output.