[英]Splitting Pandas dataframe column full of strings by unique values Python
[英]Counting unique values in a pandas dataframe column consisting mixed values of strings and list of strings
我想計算數據框特定列中的總唯一值。 該列如下所示:
df['column']=([one, two], three, four, [one,five], three])
所需的輸出是:5
我試過df['column'].nunique()
但由於列中有列表它不起作用。
我在循環中嘗試了Counter
方法,但我無法獲得總唯一計數,而是獲得了每行的唯一計數。
有誰知道如何解決這個問題?
這是一種方法:
df['column'].explode().nunique()
5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.