Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two Pandas dataframes with the same index [duplicate]

Tags:

python

pandas

I have two dataframes with the same index but different columns. How do I combine them into one with the same index but containing all the columns?

I have:

  A  1 10  2 11    B 1 20 2 21 

and I need the following output:

  A  B 1 10 20 2 11 21 
like image 396
alexsalo Avatar asked Feb 27 '15 20:02

alexsalo


People also ask

How do I merge two data frames in an index?

Merging Dataframes by index of both the dataframes As both the dataframe contains similar IDs on the index. So, to merge the dataframe on indices pass the left_index & right_index arguments as True i.e. Both the dataframes are merged on index using default Inner Join.

How do I merge two Dataframes in pandas and remove duplicates?

To concatenate DataFrames, use the concat() method, but to ignore duplicates, use the drop_duplicates() method.


1 Answers

pandas.concat([df1, df2], axis=1) 
like image 197
BrenBarn Avatar answered Sep 23 '22 00:09

BrenBarn