Categories
Python Answers

How to save a Python Pandas DataFrame table as a png

Spread the love

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')

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *