python - 根据来自例如涂鸦投票的可用性自动将参与者分配给事件
问题描述
我在 pandas DataFrame ( poll_result
) 中得到了以下(随机)类似涂鸦的民意调查结果:
import random
import names
choices = ['no','yes','Under reserve']
number_of_participants = 30
number_of_events = 6
availabilities = { names.get_full_name() : random.choices(population=choices, weights=[0.7, 0.2, 0.1], k=number_of_events) for participant in range(number_of_participants) }
poll_result = pd.DataFrame.from_dict(availabilities,orient='index')
我已经设法将人员分配到事件中,如下所示:
remaining_people = list(poll_result.index)
allocation = {}
for c in poll_result.columns:
allocation[c] = []
for rp in remaining_people:
if poll_result.loc[rp,c] == "yes":
allocation[c].append(rp)
remaining_people.remove(rp)
结果参与者名单:
for event, participants in allocation.items():
print(f"Event {event}:")
for n,p in enumerate(participants,1):
print(f"\t{n}. {p}")
print(f"\n\nPeople not allocated: {len(remaining_people)} ({', '.join(remaining_people)})")
有没有更复杂的方法来实现优化分配(最少的活动或每个活动最多的参与者)?
解决方案
推荐阅读
- python - python - pickle 引发“没有剩余空间”错误的原因?
- tslint - 打字稿:如何抑制任何分号警告
- codeigniter - 一个字段有 2 个可调用的表单验证规则
- python - Docker - 在服务之间共享本地存储
- javascript - 如何在重定向时重新渲染 React 组件
- bash - bash shell脚本从给定的时间戳中减去毫秒
- python - 如何在python的列表中存储从for循环生成的多个值类型的输出?
- windows-10 - 如何在几个小时之间限制 imacros 脚本的执行?
- python - 正则表达式 - TypeError: '>' 在 'str' 和 'int' 的实例之间不支持
- c++ - 在 Rcpp 中调用“as”没有匹配的函数