Python Forum

Full Version: pandas.Series
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have just started using pandas and I have a question related to a coding bit.
s = pd.Series(['a1', 'b2', 'c3'])
s.str.extract(r'([ab])(\d)')
I didnt quit get what the second line of code is supposed to do and I find the
r'([ab])(\d)'
a bit strange. (it is the first time I come across this kind of command).

Thank you!
It's called regular expression or short regex,more info in Python doc Regular expression operations
Pandas has it's own build way to use regex Regex in Pandas.
Quote:r'([ab])(\d)'
group 1 match a single single character a or b.
group 2 match matches a digit \d in range 0-9.
(Jul-08-2020, 10:44 AM)snippsat Wrote: [ -> ]It's called regular expression or short regex,more info in Python doc Regular expression operations
Pandas has it's own build way to use regex Regex in Pandas.
Quote:r'([ab])(\d)'
group 1 match a single single character a or b.
group 2 match matches a digit \d in range 0-9.
Thank you!