熊猫-依靠特定的列并获得前N个列表

时间:2018-09-17 04:17:57

标签: python pandas list performance

我有一个groupby,并且想> df animal age weight length 0 hamster 5 13 2 1 hamster 14 11 4 2 cat 3 14 4 3 cat 5 6 4 4 snake 7 14 8 5 cat 4 12 5 6 hamster 11 12 9 7 snake 14 9 7 8 hamster 1 5 9 9 alligator 4 13 2 10 snake 12 7 6 11 hamster 14 10 2 12 snake 7 14 7 13 alligator 4 10 2 > df.groupby("animal")['animal'].count().nlargest(3) animal hamster 5 snake 4 cat 3 依靠“动物”栏来获取列表中的前三名:

['hamster', 'snake', 'cat']

这是一种有效的方法吗,又该如何将结果的前3名转换为有序列表,即// Removes http://, https://, www. function checksDomainInitial(domain){ return domain.replace(/(http(s)?:\/\/)?(www\.)?/, ""); } console.log(checksDomainInitial("http://www.google.com")); console.log(checksDomainInitial("https://www.google.com")); console.log(checksDomainInitial("http://google.com")); console.log(checksDomainInitial("https://google.com"));

0 个答案:

没有答案