I am new in python. I have multiple same Name in the column df2, let say I don't want to drop the duplicate Name in df2.
How do I assign the values (Marks) from df1 to the same Name in df2 in different rows?
df1 = pd.DataFrame({'Name': ['rumul', 'rahul',
'ravi', 'imran'],
'Marks': [5, 20, 8, 12]})
df2 = pd.DataFrame({'Name': ['rumul', 'rahul',
'rahul', 'ravi',
'imran','ravi', 'ravi','imran','rahul','ravi'],
'Marks': ['','','','','','','','','','']})
df1
| Name | Marks |
|---|---|
| rumul | 5 |
| rahul | 20 |
| ravi | 8 |
| imran | 12 |
df2
| Name | Marks |
|---|---|
| rumul | |
| rahul | |
| rahul | |
| ravi | |
| imran | |
| ravi | |
| ravi | |
| imran | |
| rahul | |
| ravi |
The expected output:
| Name | Marks |
|---|---|
| rumul | 5 |
| rahul | 20 |
| rahul | 20 |
| ravi | 8 |
| imran | 12 |
| ravi | 8 |
| ravi | 8 |
| imran | 12 |
| rahul | 20 |
| ravi | 8 |