2

I would like to change the number format of the index of a dataframe. From the screenshot below Paper ID is all in e+07 format (I don't know how to call this btw) and I would like to change them into normal number such as 1147687 instead of 1.147687e+07.

Here's my dataframe:

teamsize dataframe

1
  • 1
    That’s scientific notation. Using floats in your index seems dangerous as hell, can you provide some context here? Commented Nov 20, 2019 at 3:52

1 Answer 1

2

You can convert your indexes values to int, but you must do it carefully, cause you can loose some ids:

df = pd.DataFrame({'PaperId':[1000000000.0, 2.0, 3.0, 4.0], 
                      'memberNum':[1, 2, 3, 4]})

df = df.set_index('PaperId')
df
            memberNum
PaperId 
1.000000e+09    1
2.000000e+00    2
3.000000e+00    3
4.000000e+00    4
df['PaperId'] = df.index
df['PaperId'] = df['PaperId'].astype('int')
df = df.set_index('PaperId')
df
        memberNum
PaperId 
1000000000  1
2           2
3           3
4           4
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.