簡體   English   中英

替換 DataFrame 中的值的問題

[英]Issues replacing values within DataFrame

我需要從 excel 工作表中的多個單元格中刪除(?),為此,我將工作表輸入到數據框中並替換需要更改的值,但是,當值以(?)結尾時 [例如' value(?)'] 使用 df.replace 我會得到錯誤

df = df.replace(to_replace='gold (?)', value='gold', regex= True)

"error: unknown extension ?) at position 1"

所以我嘗試了:

df=df.replace(to_replace="(?)", value=' ', regex= True)

這產生了相同的結果。 有小費嗎?

嘗試

df = df.replace('(?)', '')

或者,如果您想使用正則表達式,請轉義特殊字符

df = df.replace('\s+\(\?\)', '', regex=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM