dexplo / dataframe_image

A python package for embedding pandas DataFrames as images into pdf and markdown documents
https://dexplo.org/dataframe_image
MIT License
282 stars 41 forks source link

Save to remote file system #43

Closed ajmeese7 closed 2 years ago

ajmeese7 commented 2 years ago

Hey there, quick question that I am trying to help someone with. They are looking to save their dif-generated image directly to an S3 bucket on AWS without saving the image locally. Do you know of any ways to specify this currently with the library?

PaleNeutron commented 2 years ago

I am not familiar with S3 bucket but I think it will provide some api to upload files.

You could save file to disk or BytesIO and then upload it by python code.

ajmeese7 commented 2 years ago

@PaleNeutron do you have an example of how to convert the image generated by this library to BytesIO without saving it to the disk? That would be greatly appreciated!

PaleNeutron commented 2 years ago
import pandas as pd
import numpy as np
import dataframe_image as dfi
from io import BytesIO
df = pd.DataFrame(np.random.rand(5,8))
df
0 1 2 3 4 5 6 7
0 0.018129 0.511246 0.210085 0.174160 0.562191 0.533760 0.836536 0.058780
1 0.452144 0.718135 0.350870 0.881881 0.708918 0.990391 0.864563 0.440264
2 0.154236 0.069712 0.580959 0.170795 0.621348 0.202536 0.964883 0.566463
3 0.373485 0.480376 0.956419 0.230610 0.386035 0.750750 0.437797 0.030412
4 0.001774 0.984068 0.421984 0.026590 0.665637 0.395694 0.141108 0.537476
png_io = BytesIO()
df.dfi.export(png_io)
data = png_io.getbuffer()
len(data)
33341
type(data)
memoryview
PaleNeutron commented 2 years ago

You can get bytes from data, and send it to any where you want

ajmeese7 commented 2 years ago

You're the best, thanks for your help!