I would like to create a single pdf with multiple pages where each page contains a table. I have a large dataframe and I am splitting into multiple sub dataframes and I am trying to have one page each for the each sub dataframes in the pdf.
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randint(0,100,size=(150, 4)), columns=list('ABCD'))
df_list = np.array_split(df, 3)
with PdfPages('multipage_output_pdf.pdf') as pdf:
for table in df_list:
fig = plt.figure(figsize=(11.69,8.27))
ax = fig.add_subplot(111)
for row in range(len(table)):
cell_text.append(table.iloc[row])
ax.table(cellText=cell_text, colLabels=table.columns, loc='center')
ax.axis('off')
pdf.savefig(fig)
pdf.close()
I tried the above code but I am getting only one page (only one sub dataframe) in the output pdf. How should I display all the dataframes in the pdf ?