Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
x = pd.Series(['CA1234567', 'QWCEC']) x.str.extract(r'(CA|US)\d{7}$')
the expected result is [CA1234567, Nan], but get [CA, Nan].
[CA1234567, Nan]
[CA, Nan]
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]
Add a comment
Include the number in the capture group
x = pd.Series(['CA1234567', 'QWCEC']) x.str.extract(r'((CA|US)\d{7})$')
Required, but never shown
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.
Explore related questions
See similar questions with these tags.