How can I find '\[a-z]' in dataframe using reg?

Viewed 28

I'm trying to find the string with specific pattern in my dataframe

import re
import pandas as pd
import numpy as np
df = pd.read_excel(io = "mydata.xlsx", sheet_name = 'Sheet1', index_col = 0)

to find '\[a-z]' string:

header = df.select_dtypes(['object']).columns
df_header = df[header]
p = re.compile('\[a-z]')
df_header_check = df_header.apply(lambda x: x.str.contains(p, na=False))
df_header.loc[df_header_check.any(1), df_header_check.any()]

And I don't get any results. Not an error message, just an empty dataframe.

I've tried:

p = re.compile(r'\\[a-z]') but also does not work

The sample dataset:

TIME11  WARNEMOTION4    WARNEMOTION4DTL TIME12  WARNSIGN_DTL    EVENT_DTL   EVENT_DTL_2
EXCLUDE                                                                                 
1_3 1   NaN 2.0 1.0 2.0 2.0 1.0 2.0 2.0 2.0 ... NaN NaN NaN NaN NaN NaN NaN 언어: ******************  1. 변사자 정보 : ***_*****-*******_x000D__x000D_\n2. 발견일시 : ****년 **월 **일 **:**_x000D__x000D_\n3. 시도...  NaN

And I expect the dataframe output like the above.

0 Answers
Related