How to add column delimiter to Pandas dataframe display

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.

enter image description here


Try with pandas.style.apply(...):

from IPython.core.display import display, HTML

def css_border(x):
    return ["border-left: 1px solid red" if (i%2==0) else "border: 0px" for i, col in enumerate(x)]

html = (
    df.style.apply(css_border, axis=1).render()
)
display(HTML(html))