Python:Pandas在Pandas(数据框)中查找文本的可用性
我在熊猫数据框中有两列ColA ColB, 我想比较ColB和ColA如果ColA包含与ColB匹配的单词,那么我必须更新colCPython:Pandas在Pandas(数据框)中查找文本的可用性,python,regex,python-3.x,pandas,Python,Regex,Python 3.x,Pandas,我在熊猫数据框中有两列ColA ColB, 我想比较ColB和ColA如果ColA包含与ColB匹配的单词,那么我必须更新colC If it not macthes print not available. ColA ColB You can extract_insights on product reception insights u
If it not macthes print not available.
ColA ColB
You can extract_insights on product reception insights
user various sources like extract_insights etc. insights
some other sourced mail by using signals from state art text
注意:即使列A包含任何特殊字符,它也应该能够识别colB文本
期望输出:
If it not macthes print not available.
ColA ColB Colc
You can extract_insights on product reception insights AVB
user various sources like extract_insights etc. insights AVB
some other sourced mail by using signals from state art text NAVB
请尝试以下操作:
import pandas as pd
# Initialize example dataframe
data = [
["You can extract_insights on product reception", "insights"],
["user various sources like extract_insights etc.", "insights"],
["some other sourced mail by using signals from state art", "text"],
]
df = pd.DataFrame(data=data, columns=["ColA", "ColB"])
# Create column C with comparison results
df["ColC"] = [
"AVB" if (b in a) else "NAVB"
for (a, b) in zip(df["ColA"], df["ColB"])
]
print(df)
# Output:
# ColA ColB ColC
# 0 You can extract_insights on product reception insights AVB
# 1 user various sources like extract_insights etc. insights AVB
# 2 some other sourced mail by using signals from ... text NAVB
你能说清楚点吗?