1

I want to save a table with 1538 rows by 4 columns as an image, I saw this post and tried this code:

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

df = pd.read_csv('filepath.csv') 
ax = plt.subplot(111, loc='top') 
ax.xaxis.set_visible(False)  
ax.yaxis.set_visible(False)  

table(ax, df) 

plt.savefig('mytable.png')

but what I got was this, and the goal is a big image "scrollable". Is there anyway to do It?

Enzo Dtz
  • 361
  • 1
  • 16

1 Answers1

0

I realize you mentioned image, but I would look into trying to make it into an html page. Luckily, pandas can handle all of it for us with the df.to_html() method. Definitely take a look at the documentation which allows lots of nifty options (html classes, ids, borders, etc etc).

But as an example, it would look something like this:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(1538, 4),
                columns=['a', 'b', 'c', 'd'])
with open('dataframe.html', 'w') as outfile:
    outfile.write(df.to_html())

Then you can just open up dataframe.html in any browser.

Stephen C
  • 1,966
  • 1
  • 16
  • 30