How to relate a column A to B where column B starts with special characters?

Asked

Viewed 43 times

-2

inserir a descrição da imagem aqui

I have the df as indicated in the image, and would like the user to search the element of column B and return the element of column A corresponding... What I was able to do was the reverse only, search an element of A and return the B... The code I made relating column A to B:

dados.loc[dados['A']=='ALAR\AGUA_EXAUSTOR_15MH']['B']

I tried to turn B’s data into str but I could only do it with json(), which didn’t help me much.

EDIT: I was able to solve and advance what I needed by replacing the special characters. I will keep the doubt here by the curiosity to know whether right straight without replace.

Thank you to those who answer and excuse the formatting of the question because it is my first.

  • Your question makes no sense, see the Complete and Verifiable Minimum Example of your question, presents no problem at all. The only difficulty I had was to memorize the table you put as an image to avoid changing tab, in the browser, when copying the data from an image where you should have thought about the person who was interested in your question and provided a [MCVE].

  • I’m sorry I haven’t been more clear in the doubt in fact and not have provided the df.

1 answer

0


I made a little example of what you want.

One option is to filter the data and then pass the column you want and have 2 more ways that is the Loc and iloc.

import pandas as pd

dados = [
         ['Indefinido', 0]
        ,['Domingo',1]
        ,['Segunda-Feira',2]
        ,['Terça-Feira',3]
        ,['Quarta-Feira',4]
        ,['Quinta-Feira',5]
        ,['Sexta-Feira',6]
        ,['Sábado',7]
        ]

df = pd.DataFrame(dados,columns=['Dia','Numero'])
print (df)
print()

numero = int(input("Digite um número: "))

'''
#Tratamento
if numero<1 or numero > 7:
    numero = 0
'''

#Filtragem
print(df['Dia'][df.Numero==numero].to_string())

inserir a descrição da imagem aqui

Browser other questions tagged

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