0
I have a function that iterates a spreadsheet, which makes some controls. I looked over and saw about . apply, but I couldn’t implode. I would like to know if you could in that case, replace the use I use and for performance purposes, change to . apply.
In this case, I have a dictionary that he consults for my treated conditions. And the function that iterates making a loop to make this happen. The function depends on the position I pass in the dictionary and that comes from the spreadsheet to know if it displays a photo field or not.
for i, row in df.iterrows():
if row['cargo'] in cargos_to_display_photo:
df.loc[i, 'display_foto'] = True
else:
df.loc[i, 'display_foto'] = False
return df
the function that "prepares" the data frame is:
def prepare_dataframe(df_google):
df_google = set_display_photo(df_google)
return df_google
the dictionary:
cargos_to_display_photo = [
'Trainee | Assessoria de Investimentos',
'Sócio Fundador',
'Superintendente',
'Assessor de Investimentos',
'Sócia | Assessor de Investimentos',
'Líder Corporate',
'Trainee | Corporate',
]
the column I consult:
columns_dict = {
'SEXO' : 'sexo',
'CÓDIGO' : 'codigo',
'Nome Completo' : 'nome',
'Cidade' : 'unidade',
'Cargo' : 'cargo',
}
The columns that do not query or that were not cited in the excerpt I discard by the code itself, giving a drop in them with the necessary negotiations so that do not need to iterate.
the ways I researched, I couldn’t implode any. I couldn’t get apply to populate the spreadsheet. It would be possible to do this with these functions?
The code formatting of your question went bad, below the first df Return you should put the ```more to the left side. Another issue, you can make the spreadsheet available for testing?
– lmonferrari
ajustei, its link: https://docs.google.com/spreadsheets/d/1VFETvsNvA-NCFPlplCtZ1qPw3HeaCV7Te2x8kopf7ZE/edit?usp=sharing
– Wanderson Bueno Soares
@lmonferrari I took some fields from the spreadsheet because it has some confidential data. But I believe you can test.
– Wanderson Bueno Soares
Sure, no problem at all!
– lmonferrari