保存 pandas 数据帧 head(5)、统计数据并绘图为图片输出

Ten*_*zen 1 python matplotlib pandas jupyter-notebook

有什么方法可以将它们保存为 png 或其他图像输出吗?
输出图像需要包括:

df.head(5)
df[column].describe()
distribution plot
or histogram plot
Run Code Online (Sandbox Code Playgroud)

(或任何其他情节......)

小智 5

以下是您想要实现的目标的示例:

fig, ax = plt.subplots(2, 2, figsize=(20, 10))

# hide axes
# fig.patch.set_visible(False)
ax[0][0].axis('off')
ax[0][1].axis('off')
ax[0][1].axis('tight')
ax[0][0].axis('tight')

df = pd.DataFrame(np.random.rand(10, 4), columns=list('ABCD'))

ax[0][0].table(cellText=df.head().values, colLabels=df.columns, loc='center')
ax[0][1].table(cellText=df.describe().values, colLabels=df.describe().columns, rowLabels=df.describe().index, loc='center')

df.plot(kind='hist', ax=ax[1][0])
df.plot(kind='box', ax=ax[1][1])

fig.tight_layout()

plt.show()
Run Code Online (Sandbox Code Playgroud)

输出