Search number in Python text

Asked

Viewed 41 times

1

I developed a python code to search for number inside an excel file, where it has about 40 thousand data. I made a rule to bring myself only number 9 to 14, where I would classify it as phone. However besides having these phone data other numbers related to note that has 9 numbers.. Then he brings me many things of note and the telephone does not. In the text is type tel(19).... phone(19).... Could you give me a hint as to how I can make him read the string and finds type tel and from that point it records only the number.

import pandas as pd

import re

df = pd.read_excel('log1.xlsx')

df['CONTEM TELEFONE']=""

df['telefone']=""


for i in range(len(df)):

    print( i)


    t=(str (df['Observação'][i]).split(" "))

    contador =0

    contador4 =0

    while (contador <len(t)):


      if(len (t [contador])>=9 and len (t [contador])<=14):

       #print (str(t[contador]).replace("-","").replace("(","").replace(")","").replace(",",""))"

              entrada = (str(t[contador]).replace("-","").replace("(","").replace(")","").replace(",","").replace(".",""))

      contador3 = 0

      confere = 0

    while (contador3 < len(entrada)):

             if entrada[contador3:contador3+1].isdigit() == True:

                   confere = confere + 1

                   contador3 = contador3 + 1

                   if confere == len(entrada):

                      df['CONTEM TELEFONE'][i]= "sim"

                      if confere != len(entrada):

                         df['CONTEM TELEFONE'][i] ="não"

                         contador4 = contador4+1

                         if confere == len(entrada):

                          df['CONTEM TELEFONE'][i]= "sim"

                          if contador4>1:

                           df['telefone'][i] = df['telefone'][i]+";"+entrada 

                          else:

                           df['telefone'][i] = entrada 

    contador=contador +1
  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

  • Perfect, I will study the platform better before asking another question :D

No answers

Browser other questions tagged

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