[英]Python Pandas Get Unique Count of Column
I'm new to Python, lots of JS experience and SQL, and everything I've found so far is counting number of uniques for each value, but all I want is a count of unique values in the column "Team" 我是Python的新手,有很多JS经验和SQL,到目前为止我发现的所有东西都在计算每个值的唯一值,但我想要的只是“团队”列中的唯一值计数
uniqueCount= teamTable.groupby('Team').nunique()
print uniqueCount
But this only gives me the error "AttributeError: 'DataFrameGroupBy' object has no attribute 'nunique'" 但这只给我错误“AttributeError:'DataFrameGroupBy'对象没有属性'nunique'”
Thought this would be simple enough to find, but honestly can't find the function 以为这很容易找到,但老实说找不到这个功能
Date ID Team
1/1/2017 A Bears
1/1/2017 A Packers
1/1/2017 A Lions
1/1/2017 B Lions
1/3/2017 A Packers
你可以用:
len(df.Team.unique())
You can use Series.nunique
: 你可以使用
Series.nunique
:
print (df.Team.nunique())
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.