'Trying to do a script that treat Cel Numbers and put them into right format with Pandas

I,m trying to do a scrpit in python with Pandas that get data from a .CSV file and treats those data, remove letters and symbols from the Cel Phone Number Field and put them in the right format of Cel Phone Number (DDD) 00000-0000, but it clones all the data and insert them in the fields (I using Anaconda3)

The code:

dados['NMR'] = dados['NMR'].str.replace(r'[^0-9]', '')
i=0
while i < dados['NMR'].count():
    #   PREENCHE O NÚMERO COM '_' ATÉ TOTALIZAR 11 CARACTERES
    if len(dados['NMR'][i]) < 11:
        while len(dados['NMR'][i]) < 11:
            dados['NMR'] = '_' + dados['NMR'][i]
        dados['NMR'][i] = '({}) {}-{}'.format(dados['NMR'][i][0:2], dados['NMR'][i][2:7], dados['NMR'][i][7:])
        i+=1
    else:
    #   COLOCA O NÚMERO EM FORMATO DE CELULAR '(DDD) 00000-0000'
        dados['NMR'][i] = '({}) {}-{}'.format(dados['NMR'][i][0:2], dados['NMR'][i][2:7], dados['NMR'][i][7:])
        i+=1
dados['NMR']

Img from the .CSV file



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source