0

How do I join 2 dataframes on their indexes?

enter image description here

  y_final= y_test2.merge(df, left_on='index', right_on='index')
  KeyError: 'index'
3
  • 2
    Can you post dataframe examples as text? Commented May 14, 2020 at 16:34
  • 1
    We need dataframe and expected output for our reference? Commented May 14, 2020 at 16:35
  • There are multiple meanings to "join" - inner, outer, merge, update.... expected output helps narrow that down. Commented May 14, 2020 at 16:37

1 Answer 1

2

Try this one!

pd.merge(dataframe1, dataframe2, left_index=True, right_index=True)
Sign up to request clarification or add additional context in comments.

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.