1

I am trying to turn multiple dataframes into a single one based on the values in the first column, but not every dataframe has the same values in the first column. Take this example:

df1:
A    4
B    6
C    8

df2:
A    7
B    4
F    3

full_df:
A    4    7
B    6    4
C    8
F         3

How do I do this using python and pandas?

1
  • You can use Pandas' concat function for this. Commented Sep 25, 2018 at 17:26

2 Answers 2

1

You can use pandas merge with outer join

df1.merge(df2,on =['first_column'],how='outer')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I was using append.
0

You can use pd.concat, remembering to align indices:

res = pd.concat([df1.set_index(0), df2.set_index(0)], axis=1)

print(res)

     1    1
A  4.0  7.0
B  6.0  4.0
C  8.0  NaN
F  NaN  3.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.