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
  • 5,301
  • 8
  • 46
  • 120

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
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
0

You can possibly do this:

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