【问题标题】:How to combine two columns of dataframe with Nan values? [duplicate]如何将两列数据框与 Nan 值结合起来? [复制]
【发布时间】:2021-11-13 20:56:41
【问题描述】:

column1和column2合并时如何得到结果列如下?

index c1 c2 result
1 a NaN NaN
2 b c b c
3 NaN d NaN
4 NaN NaN NaN

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    用途:

    df['res'] = df['c1'].str.cat(df['c2'], sep=' ')
    print (df)
            c1   c2 result  res
    index                      
    1        a  NaN    NaN  NaN
    2        b    c    b c  b c
    3      NaN    d    NaN  NaN
    4      NaN  NaN    NaN  NaN
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2011-12-10
      • 1970-01-01
      • 2019-07-26
      相关资源
      最近更新 更多