Insert a new column in dataframe like another column only without special characters

Asked

Viewed 1,457 times

0

EX:

[[1] Reference column x New column remove special characters in a new column using dataframe pandas]

1 answer

0


Speak my dear, good morning, all right?

If I understand what you want, it can be done this way:

tabela['NOVACOL'] = tabela['COLUNAREF'].apply(lambda x: x.replace('/','')
                                          .replace('.','')
                                          .replace(';','')
                                          .replace(' ',''))

You assign to a new column tabela['NOVACOL'], the previous column tabela['COLUNAREF'] with a function applied with lambda, use the replace with the attributes, character you want to replace and substitude(empty) .

I couldn’t add the loop for in the lambda function, so it replaces the character to be removed with an iterator from a character list for example, which would make the code more pythonic and clean.

I hope it helps, hug.

Claudio.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.