繁体   English   中英

两个数据帧中短语的文本比较,并获得 output 与序列和索引匹配的短语

[英]Text comparison of phrases in two data-frames and getting the output at matching phrases with sequence and index

两个数据集 df 和 df1 在按行拆分的列中,但由句号 '.' 分隔。 作为完整的句子。 我想匹配两者中都存在的数据集短语,并在匹配句子中使用超集 df 的索引获取数据集。

如果文本是纯文本,我只能制作,但不能按列制作。 如果使用语言 model 的 spaCy 或 nlp 可以帮助处理此问题?

df:

index ID-0 ID-1 text
0 4 20 This
1 6 8 is 
2 8 6 an 
3 12 15 apple
4 29 9.
5 45 5 The
6 56 8 apple
7 60 10 is 
8 62 15 sweet
9 65 2 .
10 66 1 This 
11 68 2 is
12 70 6 very
13 73 4 good
14 75 1 fruit
15 76 3 .
16 78 1 I 
17 82 0 like
18 90 6 to 
19 95 8 eat
20 99 2 apple
21 100 0 .

df1

idx text
1 The
2 apple
3 is 
4 sweet
5 .
6 I 
7 like
8 to 
9 eat
10 apple
11 .

output:

index ID-0 ID-1 text    
5 45 5 The
6 56 8 apple
7 60 10 is 
8 62 15 sweet
9 65 2 .
16 78 1 I 
17 82 0 like
18 90 6 to 
19 95 8 eat
20 99 2 apple
21 100 0 .

应该很简单:

df_new = df[df.text.isin(df1.text)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM