简体   繁体   English

使用XlsxWriter将pandas图表插入Excel文件

[英]Insert pandas chart into an Excel file using XlsxWriter

I use python 3.4, pandas 0.14.1 and XlsxWriter 0.5.6. 我使用python 3.4,pandas 0.14.1和XlsxWriter 0.5.6。 I create a graph called 'graph' using pandas with the following code 我使用pandas创建了一个名为'graph'的图形,其代码如下

 graph=data_iter['_DiffPrice'].hist() 

, which produces a beautiful histogram. ,它产生一个美丽的直方图。

Now, how do I insert that graph into an Excel file using XlsxWriter? 现在,如何使用XlsxWriter将该图形插入Excel文件?

I tried the XlsxWriter method 我尝试了XlsxWriter方法

workbook.add_chart()

but this creates a graph in Excel, not what I want. 但这会在Excel中创建一个图形,而不是我想要的图形。

Thanks 谢谢

If you would like to export Pandas data as charts in Excel using XlsxWriter then have a look at the following how-to (that I wrote): Using Pandas and XlsxWriter to create Excel charts . 如果您想使用XlsxWriter将Pandas数据导出为Excel中的图表,请查看以下操作方法(我写的): 使用Pandas和XlsxWriter创建Excel图表

在此输入图像描述

If on the other hand you want the matplotlib style charts generated by Pandas then export them as images and insert them into a worksheet using the XlsxWriter insert_image() method. 另一方面,如果您想要Pandas生成的matplotlib样式图表,则将它们导出为图像,并使用XlsxWriter insert_image()方法将它们插入到工作表中。

See also Working with Python Pandas and XlsxWriter . 另请参阅使用Python Pandas和XlsxWriter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM