BPt.util.save_docx_table#

BPt.util.save_docx_table(df, filename, decimals=3)[source]#
Helper function for saving a dataframe to a docx file.
You must have the library python-docx installed to use this function.
Parameters
dfpandas DataFrame

The DataFrame in which to save as a docx table.

filenamestr

A path to a docx file in which to save the table. If the file already exists, then the table will be appended to the existing file, if it doesn’t already exist, then it will be created.

decimalsint, optional

An optional number of decimal points to round any floating point numbers to in the saved table.

default = 3

See also

BPt.Dataset.summary

Create and optionally save a summary of columns.

Examples

In [1]: import BPt as bp

In [2]: import pandas as pd

In [3]: df = pd.DataFrame(index=['a', 'b', 'c'])

In [4]: df.index.name = 'Subject Name'

In [5]: df['Column 1'] = [1.00, 2.00, 3.00]

In [6]: df['Column 2'] = ['A', 'B', 'C']

In [7]: df
Out[7]: 
              Column 1 Column 2
Subject Name                   
a                  1.0        A
b                  2.0        B
c                  3.0        C

In [8]: bp.util.save_docx_table(df, 'test.docx')

Which will save the following table (screenshot taken from table opened in LibreOffice):

Example Saved Table