本文整理汇总了Python中course.Course.add方法的典型用法代码示例。如果您正苦于以下问题:Python Course.add方法的具体用法?Python Course.add怎么用?Python Course.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course.Course
的用法示例。
在下文中一共展示了Course.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_courses
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import add [as 别名]
def create_courses(roster_data, keep_df=None):
"""
Create Course objects by doing one pass of roster file and using info from fields
StudentID, coursename, TeacherID. Based on the 'keeplist', determine whether a course in mandatry
Return data frame with new column that contains list of Course objects
"""
# Track courses (Course objects) that are created; will eventually be added to main roster dataframe
course_list = []
for ix, row in roster_data.iterrows():
# Info for the course
sid = row["StudentID"]
course = row["coursename"]
teachID = row["TeacherID"]
subject = row["subject"]
# Does Course already exist
exists = False
for course_obj in course_list:
course_name = course_obj.course_name
teach_id = course_obj.teacher_id
if course == course_name and teachID == teach_id:
course_obj.add(sid)
course_list.append(course_obj)
exists = True
break
# Continue if course existed
if exists:
continue
else:
# Check if there is a keep list and, if so, check if this course shoudl be listed as mandatory
keep = False
if isinstance(keep_df, pd.DataFrame):
if course in keep_df["coursename"].tolist() or subject in keep_df["subject"].tolist():
keep = True
# Create new course
new_course = Course(course, teachID, subject, keep)
new_course.add(sid)
course_list.append(new_course)
roster_data["Course"] = course_list
return roster_data