从Pandas Dataframe中删除点



我想从带有tweet的数据框中删除所有标点符号和拉丁字符,用于情感分析。代码如下。我想从列中删除标点符号,但代码删除了文本,只留下标点!!有什么建议吗?

remove_puncts =λx: re.sub("[^ A-Za-z0-9 s] +",",str (x))

df['new'] = df. tweet .apply(remove_punctuation)

尝试使用pandas.Series.str.replace

df['Tweet'].str.replace(r'[^0-9a-zA-Zs]+', '', regex=True)

示例输入:

df = pd.DataFrame({'Tweet': ['abc, def; (hij)!?', '[w] x/y: z']})
df
Tweet
0  abc, def; (hij)!?
1         [w] x-y: z
输出:

>>> df['Tweet'].str.replace(r'[^0-9a-zA-Zs]+', '', regex=True)
0    abc def hij
1         w xy z

最新更新