小编A.I*_*nfo的帖子

如何匹配第一个字符串与列和打印匹配?

我的数据框是

data = {
        'company_name' : ['auckland suppliers', 'Octagone', 'SodaBottel','Shimla Mirch'],
        'year' : [2000, 2001, 2003, 2004],
        'desc' : [' auckland has some good reviews','Octagone','we shall update you','we have varities of shimla mirch'],
}

df = pd.DataFrame(data)
Run Code Online (Sandbox Code Playgroud)

我试过这段代码

df['CompanyMatch'] = df ['company_name'] == df ['desc']
Run Code Online (Sandbox Code Playgroud)

我想打印"匹配",如果company_name列的第一个单词与desc列匹配.我很困惑,因为它放在索引[0]的位置,以便它以这种方式打印:

> company_name         desc                                 CompanyMatch
> auckland suppliers   auckland has some good reviews       Match
> Octagone             Octagone                             Match
> SodaBottel           we shall update you                  NA
> Shimla Mirch         we have varities of shimla mirch     Match
Run Code Online (Sandbox Code Playgroud)

python pandas

2
推荐指数
1
解决办法
58
查看次数

标签 统计

pandas ×1

python ×1