我很惊讶我在python中找不到任何关于排名数字的东西。。。在
基本上,我需要两个脚本来完成同一个任务—一个按升序,一个按降序。在
row[2]
是要排名的数字,row[4]
是要放入排名的单元格。
row[0] + row[1]
定义了每个数据集/组
在第一个例子中,数字越大排名越高。在
uniquedata1,uniquecell1,42,data,1,data
uniquedata1,uniquecell1,32,data,2,data
uniquedata1,uniquecell1,13,data,3,data
uniquedata2,uniquecell2,41,data,2,data
uniquedata2,uniquecell2,39,data,3,data
uniquedata2,uniquecell2,45,data,1,data
uniquedata2,uniquecell2,22,data,4,data
uniquedata1,uniquecell2,36,data,3,data
uniquedata1,uniquecell2,66,data,1,data
uniquedata1,uniquecell2,40,data,2,data
在第二个例子中,数字越大排名越低。在
在第三个例子中,这个例子是向上排列的,它包含了应该被赋予最高等级的空单元格(如果有两个空格,它们应该被赋予相同的等级)
uniquedata1,uniquecell1,42,data,2,data
uniquedata1,uniquecell1,,data,3,data
uniquedata1,uniquecell1,13,data,1,data
uniquedata2,uniquecell2,41,data,3,data
uniquedata2,uniquecell2,,data,3,data
uniquedata2,uniquecell2,,data,3,data
uniquedata2,uniquecell2,22,data,1,data
uniquedata1,uniquecell2,36,data,1,data
uniquedata1,uniquecell2,66,data,3,data
uniquedata1,uniquecell2,40,data,2,data
有人知道我怎样才能达到预期的效果吗?在
测试:
输入:
^{pr2}$输出:
如果任务的唯一区别是排名是按升序还是降序排列,那么您实际上不需要两个脚本——只需将其作为函数的参数,如图所示。
StrCount
类太琐碎了,可能不值得这么做(但我还是把它放在这里了)。在输出:
^{pr2}$如果你用熊猫,这很容易。在
我认为我在这里展示的处理NA值的行为(将它们排序为NA)可能比您在假设的示例中展示的行为更合适,但是您可以使用
fillna
在每个组中填充NA值。在相关问题 更多 >
编程相关推荐