我有一个包含多个参考值的列的数据框架。我正在尝试过滤遵循以下格式的某一组引用:
ABCD12345678
基本上前4个字符是字母后面跟着8个数字。
我试着:
df_new=df[df['col'].str.match('[a-zA-Z]', na = False)]
和
bew_2=df[df['col'].str.slice(0,4).str.contains('[a2-3]', na = False)]
但是都不起作用。如果有人能指点我一下,那就太好了。
我想你可以用
m = df['col'].str.match('^w+d+$', na = False)
# if the number is fixed
m = df['col'].str.match('^w{4}d{8}$', na = False)
print(m)
0 True
Name: col, dtype: bool