0
x = pd.Series(['CA1234567', 'QWCEC']) 
x.str.extract(r'(CA|US)\d{7}$')

the expected result is [CA1234567, Nan], but get [CA, Nan].

2 Answers 2

1

Choose the first group after the regex

In [105]: x = pd.Series(['CA1234567', 'QWCEC'])
     ...: x.str.extract(r'((CA|US)\d{7})$')[0].tolist()
Out[105]: ['CA1234567', nan]
Sign up to request clarification or add additional context in comments.

Comments

1

Include the number in the capture group

x = pd.Series(['CA1234567', 'QWCEC']) 
x.str.extract(r'((CA|US)\d{7})$')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.