Home > Net >  How to get information from excel through an input using pandas python?
How to get information from excel through an input using pandas python?

Time:11-24

How I can get information from specific lines of an excel using a variable entry placed by the user, I managed to find the information, but I can't integrate it.

import pandas as pd

dados = pd.read_excel(r"Dados.xlsx")
CPF = input('Digite o CPF: ')

if CPF in dados:
    print(dados.iloc[CPF][['CPF', 'Agencia', 'Conta']])
else:print('Não encontrado')

the iloc print works when I put the line to be printed, but I wanted the CPF indicated in the input to be the vector to search the line since the information is on the same line.

How I can get information from specific lines of an excel using a variable entry placed by the user, I managed to find the information, but I can't integrate it.

CodePudding user response:

you can see this article how-to-import-excel-file-and-find-a-specific-column-using-pandas

CodePudding user response:

If I understand well your question use this :

import pandas as pd

dados = pd.read_excel(r"Dados.xlsx")

CPF = int(input('Digite o CPF: '))

if CPF in dados['CPF'].to_list():
    print(dados.loc[dados['CPF'].eq(CPF), ['CPF', 'Agencia', 'Conta']])
else:
    print('Não encontrado')
  • Related