Menu Close

How to save a Python Pandas DataFrame table as a png

To save a Python Pandas DataFrame table as a png, we an use the savefig method.

For instance, we write

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

ax = plt.subplot(111, frame_on=False)
ax.xaxis.set_visible(False)  
ax.yaxis.set_visible(False)  

table(ax, df)

plt.savefig('mytable.png')

to call subplot to create a subplot.

We hide the frame with

ax = plt.subplot(111, frame_on=False)

We hide the x and y axes with

ax.xaxis.set_visible(False)  
ax.yaxis.set_visible(False)  

And we fill the data and plot them with

table(ax, df)

Then we save the plot with

plt.savefig('mytable.png')
Posted in Python, Python Answers