如何获得特定列的通用词?

发布于 2025-02-04 21:49:50 字数 504 浏览 3 评论 0原文

我有一个数据集,其中包含具有相同名称“名称”的两个列,我想制作一个新列“交叉”,它仅包含两个列名中的常见单词,我尝试使用各种合并或列表函数,但是我是没有得到它,有人可以帮忙吗?这是我的数据 https://githbithub.com/mayuripandey/data/data-ata-ata-apata-com-com-分析/blob/main/output.csv ”在此处输入图像描述”

I have a dataset, which contains two column with the same name 'Name', i want to make a new column 'Intersection' which contains only the common word from the two columns Name, i tried using various merge or list functions but i am not getting it, Can anyone please help? Here is my data https://github.com/mayuripandey/Data-Analysis/blob/main/output.csv enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2025-02-11 21:49:50

尝试使用各种合并或列表函数

您需要使用 set。交点 方法。您首先需要将单词提取到某些含糊的方法中以使用上述方法,请考虑以下示例

import re
text_1 = "Hello World!"
text_2 = "World of Tomorrow?"
words_1 = re.findall(r'\w+',text_1)
words_2 = re.findall(r'\w+',text_2)
common = set(words_1).intersection(words_2)
print(common) # {'World'}

请注意,我认为您将单词理解为

tried using various merge or list functions

You need to use set.intersection method. You would first need to extract words into some iterable to use said methods, consider following example

import re
text_1 = "Hello World!"
text_2 = "World of Tomorrow?"
words_1 = re.findall(r'\w+',text_1)
words_2 = re.findall(r'\w+',text_2)
common = set(words_1).intersection(words_2)
print(common) # {'World'}

Note that I assumed you understand word as 1 or more word character in re understanding and that you want to work in case-sensitive mode (therefore world, World and WORLD are different words). If latter does not hold true use casefold method of str before processing as described above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文