Saturday, 30 December 2017

Putting a pandas dataframe into word

One of the main things you will see in a report is a bunch of tables. The best way of getting this data in my world is by putting it into a dataframe and then putting this dataframe into word. Again you will probably find solutions on stack-overflow as to the best way to do this and below you will find some code that I have used for this purpose.

The basic steps to do this are:
  1. Get the data, whether from a CSV or your database, in this case I have decided to use my database to get the information. This goes into a dataframe.
  2. Prepare the word document
  3. Insert the data
The code to do this, of course with comments, is shown below and the document this produces is shown here.

The code:

1 comment: