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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Python 加快查找和替換代碼的速度?

使用 Python 加快查找和替換代碼的速度?

楊__羊羊 2022-06-28 11:09:27
我有一個需要從 pandas 數(shù)據(jù)框列中刪除的 4,000 個字符串的列表。我下面的代碼適用于下面的示例,但是當(dāng)我在我的 20k+ 行的 pandas 數(shù)據(jù)幀上使用它時,它需要很長時間。關(guān)于加快速度的任何想法?import pandas as pdimport redf = pd.DataFrame(    {        "ID": [1, 2, 3, 4, 5],        "name": [            "Hello Sam how is it going today? oh yeah",            "Hello Jane how is it going today? oh yeah",            "It is an Hello example how are you doing today?",            "how is it going today?n[soldjgf   ",            "how is it going today Hello World",        ],    })my_list = ['how is it going today?n[soldjgf', 'how are you doing today?']# =============================================================================# p = re.compile('|'.join(map(re.escape, my_list)))df['cleaned_text'] = [p.sub(' ', text) for text in df['name']] 
查看完整描述

1 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗 獲得超4個贊

使用 df.str.replace()

p = re.compile('|'.join(map(re.escape, my_list)))


df['cleaned_text'] = df['name'].str.replace(p, ' ')


查看完整回答
反對 回復(fù) 2022-06-28
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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