从熊猫插入图到Excel文件

时间:2019-05-13 08:19:23

标签: python excel matplotlib

如何将熊猫图添加到第二个工作表中,我检查了Putting multiple matplotlib graphs into Excel using Python 3,但是它们使用另一个模块来写入excel文件。一切都在代码中工作(条显示正确的输出),我只想将图添加到graph1工作表中。 到目前为止,这是我的代码

import matplotlib.pyplot as plt
from xlsxwriter import Workbook
#some code
ordered_list = csv_columns
wb=Workbook("New File.xlsx")
ws=wb.add_worksheet("New Sheet")
first_row=0
for header in ordered_list:
    col=ordered_list.index(header)
    ws.write(first_row,col,header)
row=1
for product in spider.found_items:
    for _key,_value in product.items():
        col=ordered_list.index(_key)
        ws.write(row,col,_value)
    row+=1
ws=wb.add_worksheet("graph1")
df = pd.DataFrame(spider.found_items)
counts =df.groupby('Merchant 1')['Merchant 1'].count().sort_values(ascending=False)
counts.plot(kind='bar')
#counts.plot(kind='bar')
#add to second worksheet (graph1)
wb.close()

0 个答案:

没有答案