¿Cómo agrego condicionalmente a una selección de celdas en una columna de dataframe de pandas cuando la columna es una serie de listas?

Aquí está una versión simplificada de mi dilema actual.

Aquí está el dataframe:

xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 0] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 0] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0] 

¿Cómo agrego 1 a esas celdas en la columna B donde x! = Y. Las celdas son listas y el 1 debe insertarse en el índice 1.

La tabla resultante se vería como sigue:

  xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 1] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 1] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0] 

Muchas gracias.

Esto funciona:

 def last_one(lst): lst[1] = 1 df[df.x != df.y].B.apply(last_one) 

df antes:

  xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 0] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 0] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0] 

y df después de:

  xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 1] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 1] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0] 

Podrías apply lambda:

 df[df.x != df.y].B.apply(lambda x: x[:-1] + [1]) 

Ejemplo:

 In [283]: df Out[283]: xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 0] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 0] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0] mask = df.x != df.y df.B[mask] = df.B[mask].apply(lambda x: x[:-1] + [1]) In [289]: df Out[289]: xy AB 0 ding ding [0, 1] [0, 0] 1 ding dong [0, 1] [0, 1] 2 ding ding [0, 1] [0, 0] 3 ding ding [0, 1] [0, 0] 4 ding dong [0, 1] [0, 1] 5 ding ding [0, 1] [0, 0] 6 ding ding [0, 1] [0, 0]