Pandas: Convert Dataframes to Image

Asked

Viewed 632 times

0

Given a Dataframe as the following:

df = pd.DataFrame({'id_emp' : [13524791000109, 12053850000137, 4707821000113, 4707821000114, 1],
               'name_emp': ['Cristiano', 'Gaúcho', 'Fenômeno','Angelin', 'Souza'],
               'name_dep': ['Ronaldo','Ronaldo', 'Ronaldo', 'Ronaldo', 'Bruno'],
               'weight_1': [8,9,10,11,12],
               'weight_2':[5,6,7,8,9] })

Is there a function to convert the Dataframe into some file . png, .jpg., . pdf?

1 answer

1


To convert the dataframe to image you must use the matplotlib, there is a function called imshow module matplotlib.pyplot where is passed the Feature(x_i) of the dataframe you want to mount the image and the matplotlib.pyplot the display.

If you want to save can make use of matplotlib.pyplot.savefig('imagem.png'). Below is an example of the use made available in the following post

import matplotlib.pyplot as plt
import pandas as pd
from pandas.tools.plotting import table

ax = plt.subplot(111, frame_on=False) # no visible frame
ax.xaxis.set_visible(False)  # hide the x axis
ax.yaxis.set_visible(False)  # hide the y axis

table(ax, df)  # where df is your data frame

plt.savefig('mytable.png')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.