pandas: combine two columns in a DataFrame

后端 未结 5 507
感情败类
感情败类 2020-11-30 07:42

I have a pandas DataFrame that has multiple columns in it:

Index: 239897 entries, 2012-05-11 15:20:00 to 2012-06-02 23:44:51
Data columns:
foo           


        
5条回答
  •  心在旅途
    2020-11-30 08:00

    Try this:

    pandas.concat([df['foo'].dropna(), df['bar'].dropna()]).reindex_like(df)
    

    If you want that data to become the new column bar, just assign the result to df['bar'].

提交回复
热议问题