aabujamra
aabujamra

Reputation: 4636

Python/Pandas - Duplicating an index in a new column in a Pandas DataFrame

I have a DataFrame with indexes 1,2,3.

    Name
1   Rob
2   Mark
3   Alex

I want to duplicate that index in a new column so it gets like this:

    Name  Number
1   Rob        1
2   Mark       2
3   Alex       3

Any ideas?

EDIT

I forgot one important part: those items in the Numbers column should be turned into string

Upvotes: 0

Views: 35

Answers (1)

jezrael
jezrael

Reputation: 862661

You can try:

df['Number'] = df.index.astype(str)

   Name  Number
1   Rob       1
2  Mark       2
3  Alex       3

Upvotes: 2

Related Questions