How to fill a column of a pandas dataframe using corresponding values from another column in another dataframe?

Asked

Viewed 768 times

0

Hello. I am working on a personal project and need a help. I have 2 dataframes:

solicitacoes = pd.DataFrame({'ID':[1,2,4,5],
                             'Equipe':['A','B','C','D','E'],
                             'Emissor_da_ordem':['Joao Pedro','Maria Teresa', 'Ricardo Duarte', 'Iago Matos', 'Tiago Nogueira'],
                             'Emissor_da_ordem_login':['AD_JP','CR_MT','AD_RD','0345','321'],
                             })

incidentes = pd.DataFrame({'ID':[7,8,9,10,11],
                           'Equipe':['A','B','C','D','E'],
                           'Emissor_da_ordem':'',
                           'Emissor_da_ordem_login':['AD_JP','CR_LD','AD_RD','0345','9999']
                           })

I would like to fill in each row of the incident column['Emissor_da_ordem'] with the name of its sender from its login ( incidents['Emissor_da_ordem_login'] ). Ex.: Fill in the first row of the incident column['Emissor_da_ordem'] = 'Joao Pedro'. For this I have the dataframe requests.

How can I do this with the pandas?

Note: The two tables are generated by the same system and a login corresponds to only one person. Note: Some values in incidents['Emissor_da_ordem_login'] may not be found in requests['Emissor_da_ordem_login'].

From now on, thank you very much

  • Welcome to the SO-PT, Leonardo! Your question is missing some information for the full understanding of the problem. Please read how to create a minimal and verifiable example. Take the opportunity and add in the question how should be the output of the correct answer.

2 answers

0

I don’t quite understand your question, but I believe you’re looking for it:

emissores = []
for emissor_ordem, emissor_solic, emissor_inci in zip(solicitacoes['Emissor_da_ordem'], solicitacoes['Emissor_da_ordem_login'], incidentes['Emissor_da_ordem_login']):
    if  emissor_solic==emissor_inci:
        emissores.append(emissor_ordem)
    else:
        emissores.append('')
incidentes['Emissor_da_ordem_login'] = emissores

Where the emitters were not equal, insert an empty string.

-2

Browser other questions tagged

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