我的三分之二的专栏对 .nunique() react 良好
print(df.Column1.nunique())
>>> 45
print(df.Column2.nunique())
>>> 23
但另一栏:
print(df.Column3.nunique())
..给出一个回溯,最后两行如下:
pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.unique (pandas/hashtable.c:14999)()
TypeError: unhashable type: 'RequestsCookieJar'
当你在 Jupyter 中查看 df 时,你可以在某种程度上直观地看到 cookie 之间的差异,可能会这样开始:
[<Cookie 1P_JAR=2018-03-07-09
..其他像这样:
[<Cookie 1P_JAR=2018-03-07-08
是否有一个快速修复方法可以告诉您其中有多少是唯一的?
最佳答案
看来需要:
print(df.Column3.astype(str).nunique())
或者:
print(df.Column3.apply(tuple).nunique())
关于python - 具有不可散列类型的列的唯一性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49154732/