import pandas as pd
list = ['apple','banana','cherries','dragonfruit','elderberry']
data = {'name': ['Alpha', 'Bravo','Charlie','Delta','Echo'],
'favorite_fruit': ['apple banana cherries', 'banana cherries dragonfruit',
'cherries dragonfruit','dragonfruit','apple elderberry']}
df = pd.DataFrame (data, columns = ['name','favorite_fruit'])
list我想计算df中每个水果的出现频率。预期输出:
df2
Fruit | Frequency
Apple | 2
Banana | 2
Cherries | 3
Dragonfruit | 3
Elderberry | 1
该代码df.favorite_fruit.str.split(expand=True).stack().value_counts()适用于小型 DataFrame。如果df.favorite_fruit包含数千行不同的水果组合,我如何只找到其中单词的频率list?
繁星淼淼
拉丁的传说
哆啦的时光机
相关分类