0

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

3
  • df['Number'] = df.index Commented Jan 13, 2016 at 22:59
  • This is very trivial to do Commented Jan 13, 2016 at 23:04
  • 1
    just do df['Number'] = df.index.astype(str) Commented Jan 13, 2016 at 23:36

1 Answer 1

2

You can try:

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

   Name  Number
1   Rob       1
2  Mark       2
3  Alex       3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.