示例#1
0
plt.savefig(imgname)

# generate word
document = Document()
document.add_heading('Data analysis Report', level=0)
first_student = students.iloc[0, :]['Name']
first_score = students.iloc[0, :]['Score']

p = document.add_paragraph('The highest score is student ')
p.add_run(str(first_student)).bold = True
p.add_run(', score is ')
p.add_run(str(first_score)).bold = True

p1 = document.add_paragraph(
    f'Totally {len(students.Name)} students attended the test, the summary of the testing is:'
)

table = document.add_table(rows=len(students.Name) + 1, cols=2)
table.style = 'LightShading-Accent1'

table.cell(0, 0).text = 'Student Name'
table.cell(0, 1).text = 'Student Score'

for i, (index, row) in enumerate(students.iterrows()):
    table.cell(i + 1, 0).text = str(row['Name'])
    table.cell(i + 1, 1).text = str(row['Score'])

document.add_picture(imgname)
document.save('Students.docx')
print('Done!!')