Need to change a dataframe column according to the value found in another column in Python. How to do?

Asked

Viewed 281 times

2

I need the value of a column PERTMINIST is changed from a set of words found in the column SIGLA. For example you can have in the column NOME_ORGAO the words UFJF, UFTM and update in the same row in the column PERTMINIST with string 'MEC' for example. Since there are several possible strings contained in the NOME_ORGAO column, I thought about playing in the string or set array variable. It follows code:

conmec = ['UFJF', 'UFTM','MAPA'] 
   for linha in txtosn['SIGLA_ORGAO']:
       if linha in conmec:  txtosn.set_value(linha,'PERTMINIST', 'MEC')

Imagem de parte do  DataFrame

NOTE: The above Code is placing the values correctly, but is Nan in all other columns of the same row where MEC was inserted;

No answers

Browser other questions tagged

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