1

If I have a pandas dataframe with column header "Name" and three rows (as below), how do I write a function to change the entries of "Name" such that all non-numeric characters, spaces and 0's at the front of numbers are stripped out to produce a new "Name" column as below?

Name (Before)
'John5'
'Tom  08'
'Ron 722'

Name (After)
'5'
'8'
'722'
beluga217
  • 41
  • 1
  • 4
  • Note I added a new answer on the duplicate question. But all the existing answers on the dup also look valid. – jpp Apr 01 '18 at 17:55
  • I think need `df['Name'] = df['Name'].str.extract('(\d+)', expand=False).astype(int)` – jezrael Apr 01 '18 at 18:07

0 Answers0