拯救Pandas为了人类的易读性

2024-05-13 14:28:07 发布

您现在位置:Python中文网/ 问答频道 /正文

研究熊猫描述功能。足够简单的代码:

df['Revenue'].descripe()

输出为:

enter image description here

完美。我的问题是,我希望能够将这些数据保存为png或表格,以便我可以放置在一个页面中。这是为我的EDA(探索性数据分析)我有6个主要图表或信息,我想评估每一个功能。每个图表将是一个单独的png文件。然后我将合并成一个pdf文件。我迭代了300多个特性,所以一次做一个不是一个选项,特别是看到它是每月完成。

如果您知道如何将此表保存为png或其他类似的文件格式,那就太好了。谢谢你的样子


Tags: 文件数据代码功能信息dfpdfpng
1条回答
网友
1楼 · 发布于 2024-05-13 14:28:07

另存为csv或xlsx文件

您可以使用to_csv(“filename.csv”)to_excel(“filename.xlsx”)方法以逗号分隔的格式保存文件,然后根据需要在excel中操作/格式化文件。 示例:

df['Revenue'].describe().to_csv("my_description.csv")

另存为png文件

正如注释中提到的,thispost解释了如何通过matplot lib将pandas数据帧保存到png文件。在您的情况下,这应该有效:


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

    desc = df['Revenue'].describe()

    #create a subplot without frame
    plot = plt.subplot(111, frame_on=False)

    #remove axis
    plot.xaxis.set_visible(False) 
    plot.yaxis.set_visible(False) 

    #create the table plot and position it in the upper left corner
    table(plot, desc,loc='upper right')

    #save the plot as a png file
    plt.savefig('desc_plot.png')

相关问题 更多 >