使用 pandas 对数据帧的多行进行排列
我有一个这样的数据框:
d = pd.DataFrame({'Job': ['A', 'B', 'C', 'D', 'E'],
'Machine1': [1,3,2,4,3], 'Machine2': [2,0,5,1,2]})
对于索引'Job'
,我需要找到长度为5的所有排列,基本上是(5个阶乘)排列。索引的长度可能会因不同的场景而改变,所以我并不是在寻找仅特定于 5 个作业的代码。
预期输出:A、B、C、D、E; A、C、D、E、B; E,D,C,B,A ...
等等多达120种这样的方式。在基础数学中,它是表示为 5P5 的排列
I have a data frame of this kind:
d = pd.DataFrame({'Job': ['A', 'B', 'C', 'D', 'E'],
'Machine1': [1,3,2,4,3], 'Machine2': [2,0,5,1,2]})
For the index 'Job'
, I need to find all permutations of length 5, basically (5 factorial) permutations. The length of the index may change for a different scenario, so I am not looking for a code specific to 5 jobs only.
Expected output: A,B,C,D,E; A,C,D,E,B; E,D,C,B,A ...
and so on up to 120 such ways. In basic math, it is a permutation expressed as 5P5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找内置函数
itertools .permutations()
:输出:
I think you're looking for the built-in function
itertools.permutations()
:Output: