我有两个数据帧,每行包含列表中的文本。这个叫做df
Datum File File_type Text
Datum
2000-01-27 2000-01-27 0864820040_000127_04.txt _04 [business, date, jan, heineken, starts, integr..
我还有一个,像这样的
List_type Words
0 LM_cnstrain. [abide, abiding, bound, bounded, commit, commi...
1 LM_litigius. [abovementioned, abrogate, abrogated, abrogate...
2 LM_modal_me. [can, frequently, generally, likely, often, ou...
3 LM_modal_st. [always, best, clearly, definitely, definitive...
4 LM_modal_wk. [almost, apparently, appeared, appearing, appe...
我想在df中创建新的列,在这里应该计算单词的匹配,例如df中有多少单词_lm.文字[0]英寸数据框文本[0]
注意:df有大约500行,df\u lm有6->;所以我需要在df中创建6个新列,以便更新的df看起来像这样
Datum ...LM_cnstrain LM_litigius Lm_modal_me ...
2000-01-27 ... 5 3 4
2000-02-25 ... 7 1 0
我希望我的问题是清楚的。 提前谢谢!你知道吗
编辑: 我已经做过smth了。类似的方法是创建一个列表并在其上循环,但是由于df\u lm中的列表非常长,所以这不是一个选项。你知道吗
代码如下所示:
result_list[]
for file in file_list:
count_growth = 0
for word in text.split ():
if word in growth:
count_growth = count_growth +1
a={'Grwoth':count_growth}
result_list.append(a)
根据我的评论,你可以尝试这样的方法:
下面的代码必须在循环中运行,其中第一个df中的文本列必须与下一个df中的所有6个匹配,并使用
len(c)
中的值生成列如果这对您有帮助,请告诉我,否则将更新/删除答案
因此,我得出以下解决方案:
相关问题 更多 >
编程相关推荐