Concatenate cells into a string with separator pandas python

前端 未结 5 1882
暖寄归人
暖寄归人 2021-02-14 16:53

Given the following:

df = pd.DataFrame({\'col1\' : [\"a\",\"b\"],
            \'col2\'  : [\"ab\",np.nan], \'col3\' : [\"w\",\"e\"]})

I would l

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 17:38

    for row in xrange(len(df)):
        s = '*'.join(df.ix[row].dropna().tolist())
        print s
    

提交回复
热议问题