第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 SequenceMatcher 比較 pandas 中兩列中的字符串

使用 SequenceMatcher 比較 pandas 中兩列中的字符串

繁華開滿天機(jī) 2023-05-16 14:47:13
我正在嘗試確定熊貓數(shù)據(jù)框中兩列的相似性:Text1                                                                             AllPerformance results achieved by the approaches submitted to this Challenge.       The six top approaches and three others outperform the strong baseline.Accuracy is one of the basic principles of perfectionist.                             Where am I?我想比較'Performance results ... 'with'The six...'和 ' Accuracy is one...'with 'Where am I?'。第一行應(yīng)該有較高的兩列之間的相似度,因?yàn)樗恍┰~;第二個(gè)應(yīng)該等于 0,因?yàn)閮闪兄g沒有共同的單詞。要比較我使用的兩列,SequenceMatcher如下所示:from difflib import SequenceMatcherratio = SequenceMatcher(None, df.Text1, df.All).ratio()但是 . 的使用似乎是錯(cuò)誤的df.Text1, df.All。你能告訴我為什么嗎?
查看完整描述

1 回答

?
30秒到達(dá)戰(zhàn)場(chǎng)

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊

  • SequenceMatcher不是為熊貓系列設(shè)計(jì)的。

  • 你可以.apply的功能。

  • SequenceMatcher例子

    • 偶數(shù)空格isjunk=None不被認(rèn)為是垃圾。

    • Withisjunk=lambda y: y == " "將空格視為垃圾。

from difflib import SequenceMatcher

import pandas as pd


data = {'Text1': ['Performance results achieved by the approaches submitted to this Challenge.', 'Accuracy is one of the basic principles of perfectionist.'],

? ? ? ? 'All': ['The six top approaches and three others outperform the strong baseline.', 'Where am I?']}


df = pd.DataFrame(data)


# isjunk=lambda y: y == " "

df['ratio'] = df[['Text1', 'All']].apply(lambda x: SequenceMatcher(lambda y: y == " ", x[0], x[1]).ratio(), axis=1)


# display(df)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Text1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? All? ? ?ratio

0? Performance results achieved by the approaches submitted to this Challenge.? The six top approaches and three others outperform the strong baseline.? 0.356164

1? ? ? ? ? ? ? ? ? ? Accuracy is one of the basic principles of perfectionist.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Where am I?? 0.088235


# isjunk=None

df['ratio'] = df[['Text1', 'All']].apply(lambda x: SequenceMatcher(None, x[0], x[1]).ratio(), axis=1)


# display(df)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Text1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? All? ? ?ratio

0? Performance results achieved by the approaches submitted to this Challenge.? The six top approaches and three others outperform the strong baseline.? 0.410959

1? ? ? ? ? ? ? ? ? ? Accuracy is one of the basic principles of perfectionist.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Where am I?? 0.117647



查看完整回答
反對(duì) 回復(fù) 2023-05-16
  • 1 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)