DavidK DavidK - 4 months ago 27
Python Question

How to render visually a big pandas dataframe (~7000 lines, 3 columns)?

I have a big dataframe with values between -1 and 1. The dataframe has almost 7000 lines and 3 columns. I would like to have a visualization without the cells shrinking. For now, it's more lines than cells. I would like the color to refer to the value. I was trying with

imshow
but I don't find how to increase the height of cells. I've tried to play with extent and aspect but when aspect is increased, the picture shrinks.

Answer

The most compact representation would be to use a bitmap of one pixel per value. This can be accomplished using PIL or Pillow, by creating the image from a buffer of data.

import StringIO
from PIL import Image

im = Image.open(StringIO.StringIO(buffer))

You would have to scale the data in the buffer to one or more bytes per pixel depending on the mode of the image you want to create

Comments