2017-04-23 65 views
1

我想刪除所有行從該專用文件,其中列「DB系列」包含字符*:我使用熊貓落行*

DB Serial 
0  13058 
1  13069 
2 *13070 
3  13070 
4  13044 
5  13042 

df = df[~df['DB Serial'].str.contains('*')] 

通過\

raise error, v # invalid expression 
error: nothing to repeat 

回答

3

逃生*因爲*是我:但我得到這個錯誤nterpreted爲regex

'*' Causes the resulting RE to match 0 or more repetitions of the preceding RE

df = df[~df['DB Serial'].str.contains('\*')] 
print (df) 
    DB Serial 
0  13058 
1  13069 
3  13070 
4  13044 
5  13042 

如果還可以得到:

TypeError: bad operand type for unary ~: 'float'

再投列string,因爲混合值 - 數字處理字符串:

df = df[~df['DB Serial'].astype(str).str.contains('\*')] 
print (df) 
    DB Serial 
0  13058 
1  13069 
3  13070 
4  13044 
5  13042