I want to create a column named 'texto2' that show me different outcomes according to lines of the dataframe (called text_ind). In other words, I want to write a message in case the column 'VERIF' is OK, else I dont want any message. The message will vary according to the line.
DATAFRAME
text_ind = pd.DataFrame({'ISS_2019': [10, 20, 50], 'ISS_2020': [11, 24, 40],
'change_ISS': ['10%', '20%', '-20%'],
'VAR_ISS_REAL': ['crescimento', 'crescimento', 'queda']})
DESIRED DATAFRAME
text_ind = pd.DataFrame({'ISS_2019': [10, 20, 50],'ISS_2020': [11, 24, 40],
'change_ISS': ['10%', '20%', '-20%'], 'VAR_ISS_REAL': ['crescimento', 'crescimento', 'queda'],
'texto2': ['com um crescimento real de 10% em comparao com 2019', 'com um crescimento real de 20% em comparaocom 2019', 'com uma queda real de 20% em comparao com 2019']})
script
text_ind['FLAG'] = pd.notnull(text_ind[text_ind.columns[1:2]]).astype(int)
text_ind['FLAG2'] = pd.notnull(text_ind[text_ind.columns[2:3]]).astype(int)
text_ind.loc[text_ind['FLAG'] == 1, 'VERIF'] = 'OK'
text_ind.loc[text_ind['FLAG2'] == 1, 'VERIF'] = 'OK'
text_ind['texto2'] = text_ind['VERIF'].apply(lambda x: 'com um(a) {x['VAR_ISS_REAL']}
real de {x['change_ISS']} em comparação com 2019' if x == 'OK' else '')