pandas 计算pandas中一列中唯一行的总数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46622044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 04:35:53 来源:igfitidea点击:
Count the total number of unique rows in a column in pandas
提问by ubuntu_noob
data = {
'node1': [2,2,2,3,3,5,5],
'node2': [8,16,22,5,25,10,77],
'weight': [1,1,1,1,1,1,1], }
df = pd.DataFrame(data, columns = ['node1','node2','weight'])
print df["node1"].value_counts()
This gives the output as :
这给出了输出:
2 3
3 2
5 2
But I desire the answer 3
as that is the number of unique values of rows in column node1
但我想要答案,3
因为那是列中行的唯一值数node1
回答by ubuntu_noob
Thanks @Zero
谢谢@零
df['node1'].nunique()
This works for my answer
这适用于我的答案