using regex to strip numbers inside curly braces at the start of the string in a pandas dataframe

You need to use Series.str.replace with ^\{\d+} pattern:

 df['Mese'] = df['Mese'].str.replace(r'^\{\d+}', '')

Pandas test:

>>> import pandas as pd
>>> df = pd.DataFrame({'Mese':['{12313}Luglio','{34}Maggio']})
>>> df['Mese'] = df['Mese'].str.replace(r'^\{\d+}', '')
>>> df
     Mese
0  Luglio
1  Maggio

The ^\{\d+} pattern matches a number inside curly braces at the start of the string.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top