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
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.
To concatenate DataFrames, use the concat() method, but to ignore duplicates, use the drop_duplicates() method.
pandas.concat([df1, df2], axis=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With