import pandas as pd
df = pd.DataFrame({"col1": ["a", "b", "c", ["a", "b"]]})
我有一个像这样的数据框,我想找到包含该列中列表的行。我尝试使用value_counts()函数,但它花费了很长时间,最后还报错了。以下是错误信息:
TypeError Traceback (most recent call last)
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.map_locations()
TypeError: unhashable type: 'list'
Exception ignored in: 'pandas._libs.index.IndexEngine._call_map_locations'
Traceback (most recent call last):
File "pandas/_libs/hashtable_class_helper.pxi", line 1709, in pandas._libs.hashtable.PyObjectHashTable.map_locations
TypeError: unhashable type: 'list'
c 1
a 1
[a, b] 1
b 1
Name: col1, dtype: int64
对于更大的数据框,这将需要很长时间。
以下是期望的输出结果:
col1
c 1
b 1
[a,b] 1
dtype: int64
set
也是可变的,如果他们想要类似于 set 的东西,那么它不是必须是frozenset
吗? - Cameron Riddell