pandas 如何检查每个熊猫系列值是否唯一

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48838247/
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 05:12:04  来源:igfitidea点击:

How to check every pandas series value is unique

pythonpandas

提问by Aerin

I know how to count the number of unique values in pandas series (one column in pandas dataframe).

我知道如何计算Pandas系列中唯一值的数量(Pandas数据框中的一列)。

pandas.Series.value_counts

But how do I check if they are all unique? Should I just compare value_counts with its length?

但是我如何检查它们是否都是唯一的?我应该只将 value_counts 与其长度进行比较吗?

回答by piRSquared

IIUC, pd.Series.is_unique

国际大学联盟, pd.Series.is_unique

pd.Series([1, 2, 3]).is_unique
True

And

pd.Series([1, 2, 2]).is_unique
False

回答by YOBEN_S

You can use nunique

您可以使用 nunique

pd.Series([1, 2, 3]).nunique()==len(pd.Series([1, 2, 3]))
Out[62]: True

回答by swapnil athawale

pd.Series([1,2,3,np.nan,np.nan]).is_unique

pd.Series([1,2,3,np.nan,np.nan]).is_unique

> False

> False

It will give Falsefor this which it should not.

它会False为此付出它不应该付出的代价。