Merging two dataframes using df.merge
Asked
Active
Viewed 55 times
1 Answers
0
You can try using
pd.merge(df1, df2, on=['A'])
If these are two dataframes as df1 and df2
After performing merge it becomes
Tron
- 469
- 4
- 6
-
I tried that too. It doesn't give me the second column. – K_ashyap Mar 08 '22 at 21:45
-
I've edited the answer, you just need to specify the column that you want. – Tron Mar 09 '22 at 02:41
-
It is still giving me an empty dataframe. Also, I'm reading the input from a text file. – K_ashyap Mar 09 '22 at 09:27
-
If you can share your code, then I might be able to help more. – Tron Mar 09 '22 at 10:45
-
I have edited the question – K_ashyap Mar 09 '22 at 11:08
-
I have edited the answer by changing the dfs, and changed the solution. – Tron Mar 09 '22 at 12:02
-
I tried this too. It is giving me 284083 rows x 2 columns instead of 1128 rows x 2 columns. If I try df1.merge(df2, on='ID', how='left') the second column is Nan . – K_ashyap Mar 09 '22 at 12:14
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242789/discussion-between-tron-and-k-ashyap). – Tron Mar 10 '22 at 00:38