1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
試試這個(gè),合并 2 個(gè)數(shù)據(jù)幀,將標(biāo)簽轉(zhuǎn)換為列表,添加范圍過濾器,groupby 符號(hào)并將所有標(biāo)簽連接在一起,每個(gè)符號(hào)為 1 個(gè)列表,然后使用Counterfromcollections對(duì)列表中的每個(gè)元素進(jìn)行計(jì)數(shù):
from collections import Counter
df2['Label'] = df2['Label'].str.split(',')
df = pd.merge(df1, df2, on=['Notation'])
df = df[(df['RFRange']>df['RFMin']) & (df['RFRange']<df['RFMax'])]
df = df.groupby(by='Notation', as_index=False).agg({'Label': 'sum'})
df['counts'] = df['Label'].apply(lambda x: Counter(x))
print(df)
Notation Label counts
0 AA100 [AG, IF, AG, TE, WW, AG, TE, WW, Unknown, Unkn... {'AG': 3, 'IF': 1, 'TE': 2, 'WW': 2, 'Unknown'...
1 BB200 [DT, MH, WE, DT, MH, WE, DT, MH, WE, DT, MH, W... {'DT': 5, 'MH': 5, 'WE': 5, 'Unknown': 3}
添加回答
舉報(bào)