我有一个数据框如下
+-----------+----------+-----------+--------+-------------+
|LOCATION_ID|PATIENT_ID|FACILITY_ID|DISTANCE|rank_distance|
+-----------+----------+-----------+--------+-------------+
|LOC0001 |P1 |FAC003 |54 |2 |
|LOC0001 |P1 |FAC002 |45 |1 |
|LOC0001 |P2 |FAC003 |54 |2 |
|LOC0001 |P2 |FAC002 |45 |1 |
|LOC0010 |P3 |FAC006 |12 |1 |
|LOC0010 |P3 |FAC003 |54 |4 |
|LOC0010 |P3 |FAC005 |23 |2 |
|LOC0010 |P3 |FAC002 |45 |3 |
|LOC0010 |P4 |FAC002 |45 |3 |
|LOC0010 |P4 |FAC005 |23 |2 |
|LOC0010 |P4 |FAC003 |54 |4 |
|LOC0010 |P4 |FAC006 |12 |1 |
|LOC0010 |P5 |FAC006 |12 |1 |
|LOC0010 |P5 |FAC002 |45 |3 |
|LOC0010 |P5 |FAC005 |23 |2 |
|LOC0010 |P5 |FAC003 |54 |4 |
|LOC0010 |P6 |FAC006 |12 |1 |
|LOC0010 |P6 |FAC005 |23 |2 |
|LOC0010 |P6 |FAC002 |45 |3 |
|LOC0010 |P6 |FAC003 |54 |4 |
|LOC0043 |P7 |FAC004 |42 |1 |
|LOC0054 |P8 |FAC002 |24 |2 |
|LOC0054 |P8 |FAC006 |12 |1 |
|LOC0054 |P8 |FAC005 |76 |3 |
|LOC0054 |P8 |FAC007 |100 |4 |
|LOC0065 |P9 |FAC006 |32 |1 |
|LOC0065 |P9 |FAC005 |54 |2 |
|LOC0065 |P10 |FAC006 |32 |1 |
|LOC0065 |P10 |FAC005 |54 |2 |
+-----------+----------+-----------+--------+-------------+
对于每个患者,我必须分配等级最少的设备。我的输出图应如下所示
p1 ---> FAC002 (because its rank is least)
P2 ---> FAC002 (because its rank is least)
注:除fac003容量为3外,每个设施的容量仅为2
所以对于p3,p4,p5和p6输出应该是
p3 ----> FAC006 (because its rank is 1)
P4 ----> FAC006 (because its rank is 1)
p5 ----> FAC005 (bacause FAC006 has fulled its capacity of 2,and now least
rank is of FAC005)
p6 ---->FAC005 (bacause FAC005 has one capacity left)
P7 ----->FAC004
1条答案
按热度按时间h7appiyu1#
请检查下面的代码。
基于病人从Dataframe中提取数据&用先前提取的数据检查条件,如果条件为假,则跳过该记录,否则将该记录与先前提取的记录合并。