擁有大熊貓數據幀:如何獲取熊貓數據框中的單元格值的長度?
idx Event
0 abc/def
1 abc
2 abc/def/hij
運行:df['EventItem'] = df['Event'].str.split("/")
了:
idx EventItem
0 ['abc','def']
1 ['abc']
2 ['abc','def','hij']
想要得到的各cell
的長度,運行df['EventCount'] = len(df['EventItem'])
了:
idx EventCount
0 6
1 6
2 6
如何獲得正確的計數如下?
idx EventCount
0 2
1 1
2 3
哇,'在名單.str.len'工作! – IanS