我已將孟加拉語語音翻譯成英文。但是決議后,我得到了一些垃圾字符,我想洗掉它們。我的資料框看起來像這樣。
col1
utto?tor
dokkho?shin
muuns?si
所以我想洗掉垃圾字符以及它的前一個和后一個字符。例如:在第一行中,我想洗掉? - 這個字符以及字符o和t,它們是? (this) 字符的相鄰字符。
我想要的輸出如下所示 -
col1 col2
utto?tor uttor
dokkho?shin dokkhhin
muuns?si muuni
PS我通過使用如下所示的Avro決議器獲得了這些字符:
reversed_text = avro.reverse("?????")
print(reversed_text)
output: utto?tor
col0 col1
????? utto?tor
?????? dokkho?shin
?????? muuns?si
uj5u.com熱心網友回復:
您可以使用str.replace洗掉所有非 ascii 字符和它們之前/之后的字符:
df['col2'] = df['col1'].str.replace(r'.[^\x00-\x7F].', '', regex=True)
輸出:
col1 col2
0 utto?tor uttor
1 dokkho?shin dokkhhin
2 muuns?si muuni
uj5u.com熱心網友回復:
pandas str 訪問器應該為您提供所需的功能。 https://pandas.pydata.org/docs/reference/api/pandas.Series.str.html
例子:
import pandas as pd
df = pd.DataFrame({'Col1': ['Text1', 'Text2']})
df['Col1'] = df['Col1'].str.replace("Text", "newText")
df
它還允許使用正則運算式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/526688.html
標籤:熊猫解析字符串替换孟加拉
