python中的Countif()词

我有Information Gain数据框和tf数据框。数据看起来像这样:

信息增益

    Term      IG
0   alqur     0.641328
1   an        0.641328
2   ayatayat  0.641328
3   bagai     0.641328
4   bantai    0.641328
5   besar     0.641328

学期频率

            A   B   A+B
ahli        1   0   1
alas        1   0   1
alqur       0   1   1
an          0   1   1
ayatayat    0   1   1
...        ... ... ...
terus       0   1   1
tuduh       0   1   1
tulis       1   0   1
ulama       1   0   1
upaya       0   1   1

说表信息增益= IG 和表tf = TF

如果TF'term'中包含'term'并且它的类(A / B)值为1,我想从IG计算'term'。这与excel中的COUNTIF(range_term,term)类似,但是我不知道不知道如何用熊猫或numpy或其他方式做到这一点。

pp328397830 回答:python中的Countif()词

pandas

countif=TF.loc[TF['A+B']==1,:].sum(level=0).reindex(IG.Term)
IG['COUNTIF']=countif.to_numpy()
本文链接:https://www.f2er.com/3120377.html

大家都在问