Insert a new column in dataframe equal to another column only without special characters

0

EX:

[ Column reference x new column remove special characters in a new column using pandas dataframe]

    
asked by anonymous 17.02.2018 / 23:18

1 answer

0

Speak, my dear, good morning, how are you?

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, uses replace with attributes, character you want to replace and replaced (empty).

I was unable to add the for loop in the lambda function, so it would replace the character to be removed by an iterator from a list of characters for example, which would make the code more pythonic and clean.

Hope it helps, hug.

Claudio.

    
18.02.2018 / 14:30