0

Example

I am currently trying to export a DataFrame as an excel lookalike (as you can see in the screen to be more precise). One solution is stated here, however using matplotlibs table object, doesn't allow me to customize the table like an excel lookalike.

Another solution would be to create an excel file and save the formated table as an png, I do not have access to win32com.client though and can only utilize elementary modules. How else could I solve this issue?

Bython
  • 1,135
  • 1
  • 12
  • 21
  • i once used pygame, to create a screen. then make a draw_box_with_text(x, y, text) function. then for x in row: for y in column: draw_box_with_text(x * width, y * height, value) then save that screen as an image – tgm_learn Sep 07 '22 at 14:53
  • 2
    Totally spitballing on this one, but one option might be rendering this table with the formatting you like in HTML/CSS and then using a library like `html2image` to get a png output. Interesting stackoverflow question that dovetails with this idea: https://stackoverflow.com/questions/60598837/html-to-image-using-python – JNevill Sep 07 '22 at 14:56
  • @JNevill I do not know CSS. Good idea though. Is the attached screen hard to translate into html/css? – Bython Sep 07 '22 at 14:57
  • That would definitely be a caveat. You would have to learn some html and css. I would say it's a good skill to have and it's not difficult. Just find yourself a tutorial on how to make a table in HTML and then once you get that figured out, learn how to style it with CSS. – JNevill Sep 07 '22 at 15:00
  • It looks like there is a `pretty_html_table` module that can consume from a dataframe and write out to pretty html. I would imagine there are similar modules out there if that one doesn't output the way you want. Might just be a matter of stringing together a couple of modules and calling it a day. – JNevill Sep 07 '22 at 15:16
  • FYI, `df.style.render()` returns an HTML string. Read the [documentation](https://pandas.pydata.org/docs/user_guide/style.html) on further formatting the (HTML) table. – Quang Hoang Sep 07 '22 at 15:18

0 Answers0