Pandas join/merge/concat two dataframes

前端 未结 2 730
挽巷
挽巷 2020-11-30 08:50

I am having issues with joins in pandas and I am trying to figure out what is wrong. Say I have a dataframe x:



        
2条回答
  •  失恋的感觉
    2020-11-30 09:20

    It sounds like maybe you want pandas.concat? merge and join do, well, joins, which means they will give you something based around the Cartesian product of the two inputs, but it sounds like you just want to paste them together into one big table.

    Edit: did you try concat with axis=1? It seems to do what you're asking for:

    >>> print x
              A         B         C
    0  0.155614 -0.252148  0.861163
    1  0.973517  1.156465 -0.458846
    2  2.504356 -0.356371 -0.737842
    3  0.012994  1.785123  0.161667
    4  0.574578  0.123689  0.017598
    >>> print y
             A2        B2        C2
    0 -0.280993  1.278750 -0.704449
    1  0.140282  1.955322 -0.953826
    2  0.581997 -0.239829  2.227069
    3 -0.876146 -1.955199 -0.155030
    4 -0.518593 -2.630978  0.333264
    >>> print pandas.concat([x, y], axis=1)
              A         B         C        A2        B2        C2
    0  0.155614 -0.252148  0.861163 -0.280993  1.278750 -0.704449
    1  0.973517  1.156465 -0.458846  0.140282  1.955322 -0.953826
    2  2.504356 -0.356371 -0.737842  0.581997 -0.239829  2.227069
    3  0.012994  1.785123  0.161667 -0.876146 -1.955199 -0.155030
    4  0.574578  0.123689  0.017598 -0.518593 -2.630978  0.333264
    

提交回复
热议问题