Используйте str.contains
с boolean indexing
, ~
для инвертирования логической маски:
m = df['Code'].str.contains("^[0-9]{1,5}$")
df1 = df[m]
print (df1)
No Code Name Rem Last Done LACP Chg % Chg Vol ('00)
0 1 0012 3A [S] s 0.940 0.940 - - 20
1 2 7054 AASIA [S] s - 0.205 - - -
2 3 5238 AAX [S] s 0.345 0.340 0.005 +1.47 37,806
4 5 7086 ABLEGRP [S] s 0.095 0.100 -0.005 -5.00 300
df2 = df[~m]
print (df2)
No Code Name Rem Last Done LACP Chg % Chg Vol ('00)
3 4 5238WA AAX-WA [S] s 0.135 0.135 - - 590
Detail
print (m)
0 True
1 True
2 True
3 False
4 True
Name: Code, dtype: bool
print (~m)
0 False
1 False
2 False
3 True
4 False
Name: Code, dtype: bool