The addition of chains of pandas through columns


This is perfectly legal in Python:

In [1]: 'abc' + 'def'
Out[1]: 'abcdef'

If I have an all text Pandas DataFrame, like the example below:

In [2]: df = pd.DataFrame([list('abcd'), list('efgh'), list('ijkl')],
        df.loc[[0,2], ['C2', 'C3']] = np.nan
Out[2]:     C1  C2  C3  C4
        0   a   NaN NaN d
        1   e   f   g   h
        2   i   NaN NaN l

Is it possible to do the same with columns of the above DataFrame? Something like:

In [3]: df.apply(+, axis=1) # Or

Note that both of the statements above don't work. Using in a loop is easy, but I am looking for something better.

Expected output is:

Out[3]:    C
        0  ad
        1  efgh
        2  il

You could do


Of course, this assumes that your dataframe is made up only of strings and NaNs.