在数据框中合并2列

时间:2020-10-12 08:10:10

标签: python pandas dataframe

如何将这两列合并在一起?即,我要删除NAN并将第1列(系列)移到第0列(数据框)

                                                     0              1
A    *aasvfasfdb                                                  NaN
1                                                  NaN   456,0.002121
2                                                  NaN   567,0.005298
3                                                  NaN   345,0.006192
4                                                  NaN   345,0.004532

我尝试了drop方法的不同条目,即drop(columns=0, inplace=False),但它们要么替换了一个列,要么替换了另一列。

1 个答案:

答案 0 :(得分:1)

使用df.combine_first()

In [198]: df['0'].combine_first(df['1'])
Out[198]: 
0     *aasvfasfdb
1    456,0.002121
2    567,0.005298
3    345,0.006192
4    345,0.004532