我在熊猫数据库中有两个列Cola Colb,我想将COLB与Cola进行比较,如果Cola包含匹配的单词与Colb,那么我必须更新Colc。
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