1

I have a column of phone numbers, some of the column values have ';' at the start:

Phone
-------
890734687; 098766576565
890734687
;890734687
234873576; 987982346
;9088327427; 897234632

What I need to end up with is:

Phone
-------
890734687; 098766576565
890734687
890734687
234873576; 987982346
9088327427; 897234632

Can I use a for loop?

for num in df['Phone']
    if num[0] == ';'
        # what next?
Ari
  • 3,781
  • 4
  • 34
  • 75

2 Answers2

2

Use str.lstrip:

df.Phone = df.Phone.str.lstrip(';')

Now:

print(df)

Is:

                     Phone
0  890734687; 098766576565
1                890734687
2                890734687
3     234873576; 987982346
4    9088327427; 897234632
U12-Forward
  • 65,118
  • 12
  • 70
  • 89
0

You can possibly do this:

df['Phone'] = df['Phone'].map(lambda x: x.lstrip(';'))
Om A.
  • 140
  • 6