I have two columns with strings. I would like to combine them and ignore nan
values. Such that:
ColA, Colb, ColA+ColB
str str strstr
str nan str
nan str str
I tried df['ColA+ColB'] = df['ColA'] + df['ColB']
but that creates a nan value if either column is nan. I've also thought about using concat
.
I suppose I could just go with that, and then use some df.ColA+ColB[df[ColA] = nan] = df[ColA]
but that seems like quite the workaround.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…