假設我有一個這樣的資料框:
Col1
0 Test1_2345)
1 Test2_(123
2 Test3_567)_rt
3 Test5_874)
如何從 Col1 中的字串替換 "(" 和 ")" 并擁有如下資料框:
Col1
0 Test1_2345
1 Test2_123
2 Test3_567_rt
3 Test5_874
我試過這個,但它不起作用:
df['Col1'] = df['Col1'].replace("(","",regex=True)
df['Col1'] = df['Col1'].replace(")","",regex=True)
uj5u.com熱心網友回復:
替換除\w. \w匹配字母數字字符和下劃線 _。
df1['Col1'] = df1['Col1'].str.replace('[^\w]','', regex=True)
0 Test1_2345
1 Test2_123
2 Test3_567_rt
3 Test5_874
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360956.html
