This is a Regular Expression pattern \d is a regex pattern for digit+ is a regex pattern for at least (one or more) since they are enclosed in a ( ) that means the group that you want to capture.
Hi @info.victoromondi
Thank you for you answering!!
so r'\d+' means to capture 1 digit? In the instruction, we learned {}. it means that how many time we want the number or letter to repeat. Why dont we need to use here to indicate the pattern?
You mentined that () enclosed r'\d+' mean that i want to capture the group. For example, the value is 04/2016. how can python know to capture 2016 instead of 04?
In [7]: df = pd.DataFrame({'dt':[str(num)+'/' + str(2000+num) for num in range(5)], 'name':list('victo')})
In [8]: df
Out[8]:
dt name
0 0/2000 v
1 1/2001 i
2 2/2002 c
3 3/2003 t
4 4/2004 o
In [9]: df.dt.str.extract(r"(\d+)")
Out[9]:
0
0 0
1 1
2 2
3 3
4 4