[英]Count unique values that are grouped by in Python
I am using a python database and am using pandas. 我正在使用python数据库并使用pandas。 Currently my database shows something like this:
目前我的数据库显示如下:
Employer Account_Num
AAA 123
BBB 456
AAA 789
AAA 123
BBB 101
CCC 112
I am able to put it into a table that counts all the Account_Num, which looks like this: 我可以将它放入一个计算所有Account_Num的表中,它看起来像这样:
Employer Account_Num
AAA 3
BBB 2
CCC 1
I used this code to achieve the above: 我用这段代码来实现上述目的:
bigdata.groupby(['Employer'])[['Account_Num']].count()
But I only need the unique Account_Num's counted. 但我只需要计算唯一的Account_Num。 Which should look something like this:
哪个应该是这样的:
Employer Account_Num
AAA 2
BBB 2
CCC 1
What is the best way I can achieve this? 我能做到这一点的最佳方式是什么? Thank you!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.