微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – 保存Pandas描述人类可读性

参见英文答案 > How to save a pandas DataFrame table as a png                                    6个
在熊猫上工作描述功能.简单的代码

DF [ ‘收入’].描述()

输出是:

enter image description here

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

如果你知道一种方法将这个表保存为png或其他类似的文件格式,那将是很好的.谢谢你的样子

解决方法:

保存为csv或xlsx文件

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

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

保存为png文件

正如评论中所提到的,this帖子解释了如何通过matplot lib将pandas dataframe保存到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')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐