Rename multiple column to remove spaces and comma

Solved!
FaridSuharjo
Level 1
Rename multiple column to remove spaces and comma
I try to join two data sets, but returns the following error: "Column name can not contain comma, quotation mark, leading or trailing white spaces with DSS engine"

Is there any way to remove multiple columns in mass to remove spaces and comma?
1 Solution
Alan_Fustรฉ
Level 3

Hi Farid,



You can do it with a Python Recipe using:




df.columns = df.columns.str.replace(',', '').replace(' ','')


Another option is to use a Preparation Recipe and add step "Rename Columns" but you have to change each column manually.

View solution in original post

0 Kudos
3 Replies
Alan_Fustรฉ
Level 3

Hi Farid,



You can do it with a Python Recipe using:




df.columns = df.columns.str.replace(',', '').replace(' ','')


Another option is to use a Preparation Recipe and add step "Rename Columns" but you have to change each column manually.

0 Kudos
federico_oldani
Level 2

Hello,

Old thread but I'm still having issues replacing whitespaces in columns in mass (have 500+ columns).

When using the above code, columns are changed, but all rows come out null ๐Ÿ˜•

Is there a better way to do this?

0 Kudos
federico_oldani
Level 2

NEVERMIND.

It worked in the end; thank you so much!