首页 > 解决方案 > Python Pandas - 基于条件(年/年级)的预录取决策代码规则

问题描述

我需要根据一些条件得到预录取学生选择的结果。首先,高年级的学生将优先选择班级招生(即:三年级优先于二年级,以此类推)。其次,我的排名也是基于学生在知识领域的平均成绩。因此,如果我有 3 个知识领域(数学、商业和社交),每个学生在每个领域的排名都会有所不同,具体取决于该特定领域的年份和年级。

话虽这么说,我有这个DF:

DF Rank

user_id      | area          |   year  |  mean   | rank 
10           | Social     |  3        | 9.5       | 1
11           | Social     |  3        | 9.3       | 2
12           | Social     |  2        | 9.4       | 3
13           | Social     |  2        | 9.2       | 4
14           | Social     |  1        | 9.7       | 5
15           | Social     |  1        | 9.0       | 6
10           | Business   |  3        | 9.0       | 2
11           | Business   |  3        | 9.7       | 1
12           | Business   |  2        | 9.4       | 3
13           | Business   |  2        | 9.2       | 4
14           | Business   |  1        | 8.9       | 6
15           | Business   |  1        | 9.1       | 5
10           | Math       |  3        | 9.5       | 1
11           | Math       |  3        | 9.3       | 2
12           | Math       |  2        | 9.2       | 4
13           | Math       |  2        | 9.5       | 3
14           | Math       |  1        | 9.7       | 5
15           | Math       |  1        | 9.0       | 6

该机构将为学生提供一些课程选择。将有 2 条路径,都有 3 个类选项。每个学生必须参加 2 门课程:路径 1 之一和路径 2 之一。学生将申请指向优先选择的班级:第一、第二或第三选项。每个班级都已经给了座位。

DF Offerings

oferring   |  class              |  area       |  seats
path 1     | programming         | Math        | 2
path 1     | social studies      | Social      | 2
path 1     | african history     | Social      | 2
path 2     | financial math      | Math        | 2
path 2     | startup             | Business    | 2
path 2     | democracy           | Social      | 2

最后,我有一个包含学生选择和排名的 DF。

DF Choices & Rank


offering  option user_id    class               area        year  mean    rank
Path 1  |   1   |   10  |   social studies  |   Social  |   3   |   9.5 |   1
Path 1  |   1   |   11  |   programming     |   Math    |   3   |   9.3 |   2
Path 1  |   1   |   12  |   social studies  |   Social  |   2   |   9.4 |   3
Path 1  |   1   |   13  |   african history |   Social  |   2   |   9.2 |   4
Path 1  |   1   |   14  |   african history |   Social  |   1   |   9.7 |   5
Path 1  |   1   |   15  |   social studies  |   Social  |   1   |   9.0 |   6
Path 1  |   2   |   10  |   african history |   Social  |   3   |   9.5 |   1
Path 1  |   2   |   11  |   african history |   Social  |   3   |   9.3 |   2
Path 1  |   2   |   12  |   programming     |   Math    |   2   |   9.2 |   4
Path 1  |   2   |   13  |   programming     |   Math    |   2   |   9.5 |   3
Path 1  |   2   |   14  |   social studies  |   Social  |   1   |   9.7 |   5
Path 1  |   2   |   15  |   african history |   Social  |   1   |   9.0 |   6
Path 1  |   3   |   10  |   programming     |   Math    |   3   |   9.5 |   1
Path 1  |   3   |   11  |   social studies  |   Social  |   3   |   9.3 |   2
Path 1  |   3   |   12  |   african history |   Social  |   2   |   9.4 |   3
Path 1  |   3   |   13  |   social studies  |   Social  |   2   |   9.2 |   4
Path 1  |   3   |   14  |   programming     |   Math    |   1   |   9.7 |   5
Path 1  |   3   |   15  |   programming     |   Math    |   1   |   9.0 |   6
Path 2  |   1   |   10  |   democracy       |   Social  |   3   |   9.5 |   1
Path 2  |   1   |   11  |   financial math  |   Math    |   3   |   9.3 |   2
Path 2  |   1   |   12  |   startup         |   Business|   2   |   9.4 |   3
Path 2  |   1   |   13  |   democracy       |   Social  |   2   |   9.2 |   4
Path 2  |   1   |   14  |   democracy       |   Social  |   1   |   9.7 |   5
Path 2  |   1   |   15  |   democracy       |   Social  |   1   |   9.0 |   6
Path 2  |   2   |   10  |   startup         |   Business|   3   |   9.0 |   2
Path 2  |   2   |   11  |   democracy       |   Social  |   3   |   9.3 |   2
Path 2  |   2   |   12  |   financial math  |   Math    |   2   |   9.2 |   4
Path 2  |   2   |   13  |   financial math  |   Math    |   2   |   9.5 |   3
Path 2  |   2   |   14  |   financial math  |   Math    |   1   |   9.7 |   5
Path 2  |   2   |   15  |   financial math  |   Math    |   1   |   9.0 |   6
Path 2  |   3   |   10  |   financial math  |   Math    |   3   |   9.5 |   1
Path 2  |   3   |   11  |   startup         |   Business|   3   |   9.3 |   2
Path 2  |   3   |   12  |   democracy       |   Social  |   2   |   9.4 |   3
Path 2  |   3   |   13  |   startup         |   Business|   2   |   9.2 |   4
Path 2  |   3   |   14  |   startup         |   Business|   1   |   8.9 |   6
Path 2  |   3   |   15  |   startup         |   Business|   1   |   9.1 |   5

我需要自动化注册选择。在根据学生的等级分析学生将参加哪个班级后,代码应返回学生注册。

所以,对于这个例子,前 2 名具有专业等级的学生应该参加他们选择的课程。

结果将是:

offering        class       user_id
Path 1  |   social studies  |   10
Path 1  |   social studies  |   12
Path 1  |   african history |   13
Path 1  |   african history |   14
Path 1  |   programming     |   11
Path 1  |   programming     |   15
Path 2  |   democracy       |   10
Path 2  |   democracy       |   13
Path 2  |   startup         |   12
Path 2  |   startup         |   15
Path 2  |   financial math  |   11
Path 2  |   financial math  |   14

任何人都可以帮助我吗?:)

标签: pythonpandas

解决方案


推荐阅读