我正在尝试做的是构建一个 python 脚本,该脚本按班级绘制字母等级分布,并通过电子邮件向每位教师发送所有班级分布的 PDF 文件。
脚本的电子邮件部分工作正常,情节的生成也是如此。不起作用的是没有创建 PDF 文件。
import pandas as pd
import numpy as np
import scipy
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import csv
# Import ALL grading data
print "Reading distribution.csv..."
df = pd.read_csv('distribution.csv', header=0)
# Generate the mailing list
mailing_list = df.email.unique()
# Build the PDFs
for email in mailing_list:
pp = PdfPages('grading_distribution.pdf')
filtered_df = df[df.email == email]
# Generate a course list
course_list = filtered_df.course.unique()
for course in course_list:
fig = plt.figure()
filtered_df[filtered_df.course == course].groupby('letter_grade').enrollment.sum().plot(kind='bar')
plt.title(str(course) + " Grading Distribution")
plt.xlabel("Letter Grade")
plt.ylabel("Number of Students")
fig.savefig(pp, format='pdf')
pp.close()
分布.csv:
term,course,email,letter_grade,enrollment
Summer 2014,ABC123,jdoe@gmail.com,A,1
Summer 2014,ABC123,jdoe@gmail.com,B,1
Summer 2014,ABC123,jdoe@gmail.com,B,1
Summer 2014,ARR111,jdoe@gmail.com,D,1
Summer 2014,ARR111,jdoe@gmail.com,C,1
Summer 2014,ARR111,jdoe@gmail.com,F,1
Summer 2014,XYZ987,abob@gmail.com,F,1
Summer 2014,XYZ987,abob@gmail.com,C,1
Summer 2014,XYZ987,abob@gmail.com,C,1
Summer 2014,ABC123,jdoe@gmail.com,B,1
Summer 2014,ABC123,jdoe@gmail.com,C,1
Summer 2014,ABC123,jdoe@gmail.com,C,1
Summer 2014,ARR111,jdoe@gmail.com,D,1
Summer 2014,ARR111,jdoe@gmail.com,C,1
Summer 2014,ARR111,jdoe@gmail.com,A,1
Summer 2014,XYZ987,abob@gmail.com,A,1
Summer 2014,XYZ987,abob@gmail.com,F,1
Summer 2014,XYZ987,abob@gmail.com,C,1