Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 728 Bytes

178.md

File metadata and controls

38 lines (31 loc) · 728 Bytes
@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
[上一个例子](177.md) [下一个例子](179.md)