1

I need to replace all the spaces in a dataframe column with a period. ie:

Original df:

    symbol
0   AEC
1   BRK A
2   BRK B
3   CTRX
4   FCE A

Desired result df:

    symbol
0   AEC
1   BRK.A
2   BRK.B
3   CTRX
4   FCE.A

Is there a way to do this without needing to iterate through each row, replacing the space one at a time? I prefer not to iterate one row at a time if there is a vectorized way to do things.

darkpool
  • 13,822
  • 16
  • 54
  • 89

1 Answers1

6

Use vectorised str.replace:

In [95]:
df['symbol'] = df['symbol'].str.replace(' ','.')
df

Out[95]:
  symbol
0    AEC
1  BRK.A
2  BRK.B
3   CTRX
4  FCE.A
EdChum
  • 376,765
  • 198
  • 813
  • 562