Normally can do this for dataframes without multi index:
import docx
df = pd.DataFrame(data)
doc = docx.Document('./test.docx')
t = doc.add_table(df.shape[0]+1, df.shape[1])
for j in range(df.shape[-1]):
t.cell(0,j).text = df.columns[j]
for i in range(df.shape[0]):
for j in range(df.shape[-1]):
t.cell(i+1,j).text = str(df.values[i,j])
doc.save('./test.docx')
The problem arises with multi index in DataFrame the output is empty. How to resolve this issue?