我想计算数据帧特定列中的唯一值总数。该列如下所示:
df['column']=([one, two], three, four, [one,five], three])
所需的输出将是:5
我尝试过df['column'].nunique()
,但由于该列中有列表,所以它不起作用。
我在一个循环中尝试了Counter
方法,但是我无法获得总的唯一计数,但是我却获得了每行的唯一计数。
有人知道如何解决吗?
这是一种方法:
df['column'].explode().nunique()
5