Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

This is my data:

  INF  CTR  Time 

A  1    8     3

B  5    1     3

C  3    2     3

And I have another set of data with these same elements, but different collumn names:

  INF2  CTR2  Time 

A  3    1     3

B  6    4     3

C  1    7     3

I need to merge the data like this:

  INF  CTR  INF2  CTR2  Time 

A  1    8     3    1     3

B  5    1     6    4     3

C  3    2     1    7     3

How can I do it?

1 Answer

0 votes
by (36.8k points)

When you want to join the indexes use the .join(), otherwise pd.merge():

df1.join(df2[['INF2', 'CTR2']])

Merging on indexes looks like this:

pd.merge(

    df1, 

    df2[['INF2', 'CTR2']], 

    left_index=True, 

    right_index=True,

)

 Want to be a master in Data Science? Enroll in this Data Science Courses

Browse Categories

...