![](/img/trans.png)
[英]How to count the number of unique elements in a column in a Pandas dataframe
[英]How to know the number of elements in a column that are stored as an array in Pandas dataframe
我有一個數據框的結果,如下所示:
Factor OccurIn
Accelerator [41, 81, 62]
Breaks [51, 11, 12, 13]
Vision [58, 31, 92, 67, 68]
如何將該幀復制到一個新的幀中,該幀有一列總結了數組中元素的數量,例如:
Factor n
Accelerator 3
Breaks 4
Vision 5
你可以做
df['n']=df['OccurIn'].str.len()
或者
df['n']=df['OccurIn'].map(len)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.