dataframe_image icon indicating copy to clipboard operation
dataframe_image copied to clipboard

Dataframe as PNG object

Open itang1 opened this issue 3 years ago • 6 comments

Can we get the ability to return the styled Dataframe as a PNG object, without needing to save the image?

Even though dfi.export() is currently broken with respect to several situations (including on Google Colab), once I have the image object, I can use other means to save it.

This would address several issues, including #6 #7 #9 #13 #15

itang1 avatar May 09 '21 06:05 itang1

Seconded, exporting the image into buffer / loading it into an array would be great, because that would allow us to show that image with plotting libraries like matplotlib.

znstrider avatar Jun 06 '21 19:06 znstrider

Is there any workaround for this issue?

mvinoba avatar Jul 29 '21 23:07 mvinoba

The only "workaround" is to save the image to disk temporarily.

kampelmuehler avatar Aug 04 '21 07:08 kampelmuehler

You can feed it to a BytesIO object and show it in jupyter with Image from Ipython.display

LiZhongyangLi avatar Dec 16 '21 15:12 LiZhongyangLi

@LiZhongyangLi I'm confused how that helps with downloading the styled object as a PNG file if all we're doing is displaying it

andrewqho avatar Dec 16 '21 19:12 andrewqho

Any update on this? Would be handy to have the image as an object

JoeTinnySpace avatar Apr 14 '22 06:04 JoeTinnySpace

It is easy and not related to this package. Just use io.BytesIO instead of filename.

import pandas as pd
import numpy as np
from io import BytesIO
import dataframe_image

bio = BytesIO()
df = pd.DataFrame(np.random.randint(0, 100, size=(30, 20)))
df.dfi.export(bio)
image_data = bio.read()
# do whatever you want

PaleNeutron avatar Aug 29 '23 02:08 PaleNeutron