我要做的是构建一个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()
distribution.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