-1

I'm trying to format the mobile numbers (In a column data frame). So, I did a function that formats for me, but I need to apply it in an existent column in my data frame, but when I use the apply() function with my new function, it returns just None in my column. Can someone help, please?

def tranformarNum(celular):
    celular = str(df.Celular)
    
    if len(celular) == 8:
        if celular[0] == '9' or celular[0] == '8' or celular[0] == '7':
            celular = '619'+celular
        
        elif celular[0] != '9' or celular[0] != '8' or celular[0] != '7':
            celular = '61'+celular
        
    elif len(celular) == 9:
        if celular[0] == '9' or celular[0] == '8' or celular[0] == '7':
            celular = '61'+telefone
            
    elif len(celular) == 10:
        if celular[2] == '3' or celular[2] == '4' or celular[2] == '5':
            telefone
            
        else:
            celular = celular[2:]
            celular = '619'+celular
        
    elif len(celular) == 11:
        celular
        
    else:
      print('Telefone Inválido')
    
df['Celular'] = df['Celular'].apply(tranformarNum)

df['Celular'] is the columns that I want to subscript the numbers for the formated numbers using my function.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 2
    Presumably the function is supposed to return something. Since you didn't put a `return` statement, it returns `None`. – mkrieger1 May 06 '21 at 23:28

1 Answers1

3

You need to return celular from your function. You're getting None because the function never returns a value.

sweil
  • 41
  • 2