Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas style doesn't work with Google colab

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

like image 966
Roy2012 Avatar asked Jun 08 '20 05:06

Roy2012


People also ask

What version of pandas does Google colab use?

As I understand in Google Colab environment pandas is pre-installed. However the version it use it's not the recent one. It is still use the 0.22.

Does cv2 work on Colab?

Note: The imshow method of cv2 is disabled in Google Colab. Thus, colab users need to import cv2_imshow for displaying images. So the commands will be like: Jupyter Notebook: cv2.

Can I use pandas_profiling on Google Colab?

However, pandas_profiling cannot be straightforwardly used on Colab. The code will result in an error, as below; This is because Google Colab comes with a pre-installed older version of Pandas-profiling (v1) and the join_axes function is deprecated in the installed Pandas version on Google Colab.

Why join_axes() is not working in Google Colab?

This is because Google Colab comes with a pre-installed older version of Pandas-profiling (v1) and the join_axes function is deprecated in the installed Pandas version on Google Colab. STEPS : Install Pandas Profiling on Google Colab. 1. Run the below command, you can visit the link on github.

Is profile to_widgets() not working on Google Colab?

However, profile.to_widgets () will not be working properly as it is not yet fully supported on Google Colab, as below snapshot : 7. Instead, change to profile.to_notebook_iframe (), as below snapshot: 8. Save your output file in html format: so you can share as a webpage

Is there a way to run the Colab frontend locally?

There's no way to run the colab frontend locally. To note, however, that Colaboratory lets you connect to a local runtime using Jupyter. This allows you to execute code on your local hardware and have access to your local file system (it's a Colab frontend with a local runtime). If that is your goal, here you can find a way to do that.


1 Answers

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?

like image 85
Attack68 Avatar answered Oct 23 '22 20:10

Attack68