Python 如何替换列中除字母和数字以外的所有内容?
我有一个类似这样的df:Python 如何替换列中除字母和数字以外的所有内容?,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个类似这样的df: id answer 1 how are you? 2 What's the word in the letters' 3 .... \xa0 \xa0' Hey what's up? 我如何用df.answer中的零替换所有不是字母或数字的东西 新df将如下所示: id question 1 how are you 2 Whats the word in the letters 3 Hey w
id answer
1 how are you?
2 What's the word in the letters'
3 .... \xa0 \xa0' Hey what's up?
我如何用df.answer中的零替换所有不是字母或数字的东西
新df将如下所示:
id question
1 how are you
2 Whats the word in the letters
3 Hey whats up
这应该行得通
这应该是可行的。您也可以使用模块:
另一种选择:
df['words'].str.replace(r'\W+&\s', '')
您还可以使用模块:
另一种选择:
df['words'].str.replace(r'\W+&\s', '')
这是如何摆脱“Quest1”的?这是如何摆脱“Quest1”的?而不是使用
apply
和lambda
-为什么不使用相同的表达式使用df['words'].str.replace('regex here')
?而不是使用apply
和lambda
-为什么不使用相同的表达式使用df['words'].str.replace('regex here')
?
df['words'].str.replace(r'\W+&\s', '')