1

I'd like to add data from a dataframe to a another dataframe.

Here my first data frame: df

enter image description here

Here my second dataframe: dff

enter image description here

df.append(dff, ignore_index=True, sort=False)

And it results me that:

enter image description here

5
  • df.combine_first(dff) ?? Commented Mar 1, 2019 at 13:06
  • try df.merge(dff, on='Postal Code'), or it has to be added based on other logic? Commented Mar 1, 2019 at 13:06
  • in fact only df.merge(dff) should be sufficient, since Postal Code is the only common column Commented Mar 1, 2019 at 13:09
  • try result = pd.concat([df, dff], ignore_index=True, sort=False) Commented Mar 1, 2019 at 13:09
  • 3
    Please DO NOT post samples in images, it is always recommended to post samples as a text with CODE TAGS @Info Digitalevo kindly edit your post and do let us know then. Commented Mar 1, 2019 at 13:15

2 Answers 2

3

Appending is adding two dataframe 'on top of each other' so you add rows. If you want to add new columns to your dataframe from another dataframe, you use join or merge especially if you have a key column where you can merge, which is in your case Postal Code

In pandas we use pd.merge for merging two dataframes with each other like the followng:

df_final = pd.merge(df, dff, on='Postal Code')


    Postal Code     Borough     Neighbourhood   Lattitude   Longitude
0   M1B             Scarborough Rouge           43.806686   -79.194353
1   M1B             Scarborough Malvern         43.806686   -79.194353
2   M1C             Scarborough Port Union      43.784535   -79.160497
3   M1C             Scarborough Rouge Hill      43.784535   -79.160497
4   M1C             Scarborough Highland Creek  43.784535   -79.160497
Sign up to request clarification or add additional context in comments.

Comments

0

I think merge is what you're looking for.

df.merge(dff, on='Postal Code')

should do the trick.

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.