Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas.Series
#1
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!
Reply
#2
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.
Reply
#3
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  created a pandas series instead of pandas DataFrame ibaad1406 6 3,633 Sep-06-2019, 06:23 AM
Last Post: ibaad1406
  create 10 yearly blocks from time series using pandas Staph 1 1,962 Jul-23-2019, 12:01 PM
Last Post: Malt
  [pandas]How to liner fit time series data and get linear fit equation and r square Sri 5 3,804 Apr-04-2019, 12:00 PM
Last Post: Sri
  Manipulating Series in Dataframe (Pandas) wendysling 2 2,721 Mar-26-2019, 07:12 PM
Last Post: wendysling

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020