0

given two data frames:

a=pd.DataFrame({'col1':[1],'col2':[4]},index=[0])
b=pd.DataFrame({'col3':[7],'col4':[8]},index=[1])

how do I get dataframe c:

c=pd.DataFrame({'col1':[1],'col2':[4],'col3':[7],'col4':[8]},index=[1])

2 Answers 2

1

Try this .i believe you can use the append

c = a.append(b,True)
Sign up to request clarification or add additional context in comments.

1 Comment

,thanks. But there's a mismatch of index between a and b. You solution gives a dataframe with two rows. How can I get a one row result?
1

Because you have a mismatch on your indices you have to overwrite them:

In [66]:

a.index=b.index
pd.concat([a,b], axis=1)
Out[66]:
   col1  col2  col3  col4
1     1     4     7     8

If you didn't do this then you get an additional row:

In [71]:

pd.concat([a,b], axis=1)
Out[71]:
   col1  col2  col3  col4
0     1     4   NaN   NaN
1   NaN   NaN     7     8

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.