當前位置: 首頁>>代碼示例>>Python>>正文


Python Course.add方法代碼示例

本文整理匯總了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
開發者ID:jbg24,項目名稱:SurveyAdmin,代碼行數:52,代碼來源:sample.py


注:本文中的course.Course.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。