-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
New Feature Request: Export plots to excel/pdf #2302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you want to export a matplotlib plot as an image to the Excel report or actually create an Excel plot? |
If both can be done then great, but I was specifically looking to export a matplotlib plot as an image to the Excel report. |
Excel plots: openpyxl has a charting API you can use for now |
Code to get a picture to excel: Create a workbookwb = Workbook() Add a sheet/tabws0 = wb.add_sheet('Picture_Test') Write text to cell at location (0,1)ws0.write(0, 1, "Moving Average") Add picture at location (2,1)Note: Only accepts bmp filesi.e. ws0.insert_bitmap('C:\Users\username\Desktop/test.bmp', 2, 1)ws0.insert_bitmap('test.bmp', 2, 1) Write excel fileNote: This will overwrite any other files with the same namewb.save('hello.xls') ** The only remaining issue is getting both the dataframe and the picture in the same excel file and in seperate tabs |
Please escape your #s with a slash :) |
Entire code to export df and a bmp to excel using xlwt: from xlwt import * Create a dataframe with dates as your indexdata = [1,2,3,4,5,6,7,8,9,10] Create a workbookwb = Workbook() Add a sheet/tabws0 = wb.add_sheet('Picture_Test') Write text to cell at location (0,1)ws0.write(0, 1, "Moving Average") Write dataframedate_xf = easyxf(num_format_str='DD/MM/YYYY') # sets date format in Excel Add picture at location (2,1)Note: Only accepts bmp filesi.e. ws0.insert_bitmap('C:\Users\username\Desktop/test.bmp', 2, 1)ws0.insert_bitmap('test.bmp', 2, 1) Write excel fileNote: This will overwrite any other files with the same namewb.save('hello.xls') |
@pichonz you have another option with |
@jmcnamara package and docs are excellent, plenty good enough so that pandas needn't handle I added it to the cookbook a while ago, but not the pandas ecosystem section of the docs @jmcnamara all your docs are beautiful, what's your secret? |
Yes. I'll look into that.
Late nights and good templates. And thanks. |
@jmcnamara I totally agree with @y-p - great work on that package - very impressive! |
The current functionality to export dataframes to excel is excellent:
i.e. df.to_excel('filename')
In the process of introducing python to my company, I realized I needed to not only export the dataframes but also plots. I searched but did not find this functionality. This is more of a reporting need, but would be very useful.
The text was updated successfully, but these errors were encountered: