title: Applying a function in a dataframe column with rows that have inconsistent content
body: <p>I have this dataframe:</p>
  
  <pre><code>      data          
  0   [dic_inside_list_1]
  1   [dic_inside_list_2]  
  ...
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>dic_inside_list_1 = [{'tipo': 'ATIVA', 'nome': 'GABRIEL FRANCISCO DA CUNHA', 'advogado': False, 'advogados': [{'tipo': 'ADVOGADO_PARTE_ATIVA', 'nome': 'PATRICIA DE SIQUEIRA MANOEL DUARTE', 'advogado': True}]}]
  
  dic_inside_list_2 = [{'tipo': 'ATIVA', 'nome': 'JOSÉ FRANCISCO DE OLIVEIRA', 'advogado': False, 'advogados': [{'tipo': 'ADVOGADO_PARTE_ATIVA', 'nome': 'JULIO TORSO ALCANTARA', 'advogado': True}]}, {'tipo': 'PASSIVA', 'nome': 'INDUSTRIAS MENTEN DE CARTONAGEM LTDA', 'advogado': False, 'advogados': []}]
  </code></pre>
  
  <p>I want to create two new columns: "parte_passiva" and "parte_ativa"
  "parte_ativa" is getting "nome" from the dictionary that has "tipo" as "ATIVA"
  "parte_passiva" is getting "nome" from the dictionary that has "tipo" as "PASSIVA"</p>
  
  <p>So it should look like this:</p>
  
  <pre><code>                   data                    parte_ativa             parte_passiva
  0   [dic_inside_list_1]   'GABRIEL FRANCISCO DA CUNHA'     
  1   [dic_inside_list_2]   'JOSÉ FRANCISCO DE OLIVEIRA'    'INDUSTRIAS MENTEN DE CARTONAGEM LTDA'
  ...
  </code></pre>
  
  <p>The following code worked for "parte_ativa" since that's present in both dictionaries:</p>
  
  <pre><code>df['parte_ativa']=df['data'].apply(lambda x: x[0]['nome'] if x[0]['tipo']=='ATIVA' else x)
  </code></pre>
  
  <p>However when I try to apply that to parte_passiva <code>df['parte_passiva']=df['data'].apply(lambda x: x[1]['nome'] if x[1]['tipo']=='PASSIVA' else x)</code> it raises an error since not all rows have <code>'tipo' == 'PASSIVA'</code></p>
  
  <pre><code>IndexError: list index out of range
  </code></pre>
  
  <p>Does anyone have a suggestion for that?
  I know that it is not possible to put a try sentence inside lambda. Is there a way to use if sentences to prevent that from happening?</p>