@author jackzhenguo
@desc apply 方法去掉特殊字符
@tag
@version
@date 2020/03/16
apply 方法去掉特殊字符
某列单元格含有特殊字符,如标点符号,使用元素级操作方法 apply 干掉它们:
import string
exclude = set(string.punctuation)
def remove_punctuation(x):
x = ''.join(ch for ch in x if ch not in exclude)
return x
# 原df
Out[26]:
a b
0 c,d edc.rc
1 3 3
2 d ef 4
# 过滤a列标点
In [27]: df.a = df.a.apply(remove_punctuation)
In [28]: df
Out[28]:
a b
0 cd edc.rc
1 3 3
2 d ef 4
大家在看
AI安装教程
AI本地安装教程
微软AI大模型通识教程
微软AI大模型通识教程
AI大模型入门教程
AI大模型入门教程
Python入门教程
Python入门教程
Python进阶教程
Python进阶教程
Python小例子200道练习题
Python小例子200道练习题
Python练手项目
Python练手项目
Python从零在线练习题
Python从零到一60题