2017-04-23 1 views
1

나는이 칼럼은 'DB 시리얼'문자 * 포함하는 경우 DF에서 모든 행을 삭제하기 위해 노력하고있어 :팬더 *이 행을 드롭

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 
관련 문제