Search code examples
pythonpandasdataframejupyter-notebookhtml-email

How do I send a styled pandas DataFrame by e-mail without losing the format?


I am pretty new to Python and to the Jupyter Notebook. So any help will be appreciated. I was able to color specific cells of my DataFrame following this question.

Now suppose that I have that table with the "style" on it (as the one in the accepted answer) and I wish to send it by e-mail to someone (in this case, myself) without losing any of the format (it should contain the colored cells, the border, and everything else).

I have tried using the .render() function and then attaching the HTML code to the body of the e-mail but I keep getting a borderless table with no structure. I have followed this post to code the e-mail part. The only difference is that I am not using the "plain text" part.

Also, how can I add more features to the table itself? Like adding table title, modify the spacing between the columns, increasing or decreasing the font size?

Thank you!


Solution

  • I was able to find an answer to my question following this post: how to draw a beautiful colorful table with pandas or other package in Python?

    Essentially, if you use the .set_table_styles to add the borders after adding the colors to the cells, the html code sent by e-mail will be displayed properly. I hope it helps anyone with the same issue.