Suppose I have the following dataframe:
d = {'col1':['apple; kiwi; banana','orange; apple','apple', 'apple, orange, melon']}
df= pd.DataFrame(d)
to get :
col1
0 apple; kiwi; banana
1 orange; apple
2 apple
3 apple, orange, melon
I want to count how many times apple
comes in association with other fruits. If I do df.value_counts()
I can see that each element is counted once only. I would want to know however how times apple
are in coming in different cell length, as in apple
has two cells that have 3 string, 1 cell with 2 string and 1 cell in 1 string. So the outcome would be:
len of string number for apple
0 1 1
1 2 1
2 3 2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…