0

I have a dataset with severals columns containing numbers and I need to remove the ',' thousand separator.

Here is an example: 123,456.15 -> 123456.15.

I tried to get it done with multi-indexes the following way:

toProcess = ['col1','col2','col3']
df[toProcess] = df[toProcess].str.replace(',','')

Unfortunately, the error is: 'Dataframe' object has no attributes 'str'. Dataframe don't have str attributes but Series does.

How can I achieve this task efficiently ?

Here is a working way iterating over the columns:

toProcess = ['col1','col2','col3']
for i, col in enumerate(toProcess):
    df[col] = df[col].str.replace(',','')
Olivier D'Ancona
  • 779
  • 2
  • 14
  • 30

1 Answers1

1

Use:

df[toProcess] = df[toProcess].replace(',','', regex=True)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252