0

Is is possible to fetch column containing values corresponding to an id column? Example:-

df1

|   ID     | Value   | Salary |
|:---------:--------:|:------:|   
|    1     |   amr   | 34     |
|    6     |   ith   | 67     |
|    2     |   oaa   | 45     |
|    1     |   amr   | 78     |
|    3     |   anik  | 56     |
|    4     |   mmkk  | 99     |
|    5     |   sh_s  | 98     |
|    5     |   sh_s  | 77     |
df2

|   Value  | Dept    | days   |
:----------:---------:--------:
|    amr   |   hrs   | 1      |
|    ith   |   cse   | 2      |
|    oaa   |   me    | 3      |
|    eea   |   ece   | 5      |
|    anik  |   eee   | 6      |

Expected Output
|   ID     | Dept    | Value     |
|:---------:--------:|----------:|
|    1     |   hrs   | amr       |
|    1     |   cse   | ith       |
|    2     |   me    | oaa       |
|    1     |   ece   | eea       |
|    3     |   eee   | anik      |

I want to fetch each values in the 'ID' column corresponding to values in df2's ID column. And create column containing 'ID' in df2. The number of rows in the two dfs are not the same. I have tried

this

I got this error InvalidIndexError: Reindexing only valid with uniquely valued Index objects

Amzzz
  • 45
  • 1
  • 1
  • 7

0 Answers0