12

I'm facing a strange behavior with Google colab and pandas style. When applying a style to a dataframe on google colab, some of the basic styling is messed up: the table becomes smaller and more condensed, the highlight of every other row disappears, and the hover highlight of rows stops working.

I'm attaching a side-by-side picture of two screenshots: one from a regular Jupiter notebook, in which things are working fine, and another one from Google colab - in which styling messes up things.

The code is extremely simple:

df = pd.DataFrame(range(5)) # create a data frame

df                          # in a new cell - just show the dataframe

df.style.highlight_max()    # again, in a new cell. Works in Jupyter notebook, 
                            # doesn't work well on Google Colab. 

Any help would be appreciated.

enter image description here

Roy2012
  • 11,755
  • 2
  • 22
  • 35

3 Answers3

1

I don't think this is pandas styler. All pandas does is render HTML which works well in Notebook or normal browsers. (Jupyter has its own set of CSS that it applies to rendered tables). Google colab will have their own set of CSS.

I suspect the hierarchy of colab's default CSS is not as dominant as Jupyters. Maybe file an issue with them?

Attack68
  • 4,437
  • 1
  • 20
  • 40
0

It is the issue with html rendering of Colab but you could try something like this to fix it although it does not give the exact same results as notebook does.

df.style.highlight_max(axis=0).set_properties( **{'width': '30px'},**{'text-align': 'center'})

Output:

center aligned style

iamarchisha
  • 175
  • 7
0

It worked for me:

import pandas as pd
df = pd.read_csv('/content/drive/My Drive/Colab Notebooks/teste.csv')
df.head(100).style.highlight_max(axis=0).set_properties( **{'color': 'red'})

however it does not work with this feature:

%load_ext google.colab.data_table
Deivdy
  • 1