How to merge two dataframes side-by-side?

前端 未结 3 1679
耶瑟儿~
耶瑟儿~ 2020-11-30 09:47

is there a way to conveniently merge two data frames side by side?

both two data frames have 30 rows, they have different number of columns, say, df1 has 20 columns

3条回答
  •  青春惊慌失措
    2020-11-30 10:27

    I came across your question while I was trying to achieve something like the following:

    So once I sliced my dataframes, I first ensured that their index are the same. In your case both dataframes needs to be indexed from 0 to 29. Then merged both dataframes by the index.

    df1.reset_index(drop=True).merge(df2.reset_index(drop=True), left_index=True, right_index=True)
    

提交回复
热议问题