0

Is there a quick way in panda that I can add a column containing numbers which uniquely indexes (I am not sure if it is the correct terminology) one of the columns of the table?

E.g. there is such a table:

     A      B
0  foo    one
1  bar    one
2  foo    two
3  bar  three
4  foo    two
5  bar    two
6  foo    one
7  foo  three

if the newly added column is "id" and the uniquely indexed column is A, the result should be:

     A      B   id
0  foo    one    1
1  bar    one    2
2  foo    two    1
3  bar  three    2
4  foo    two    1
5  bar    two    2
6  foo    one    1
7  foo  three    1 

Thanks in advance

Aqqqq
  • 816
  • 2
  • 10
  • 27

0 Answers0