1

I am working with python / pandas.

My dataframe contains one column called 'id' with 20-digit IDs like 1225485903482773506 with datatype float. If I convert the column to string with

df['id'] = df['id'].apply(str)

They come out as something like this 1.289050198535111e+18

How do I convert them to string without the scientific notation?

1
  • can you print df.dtypes Commented Sep 16, 2020 at 23:43

2 Answers 2

3

You need to apply a string formatter to it, instead of just wrapping it in a string. Specifically you can:

df["id"].apply("{:.0f}".format)

You can simply change "{:.0f}" to "{:.1f}" or "{:.2f}" ... "{:.nf}" to be able to keep 0, 1, 2, ... n decimal places respectively.

Or if you want to see all numbers to the right of the decimal, then this should work:

df["id"].apply("{:f}".format)
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't appear to work: "{:f}".format(0.000000234234234) produces 0.000000.
If you want more decimal places than the default you can try adding in a larger value to the format-specification: df["id"].apply("{:.32f}".format)
why there is wrong result : "{:f}".format(27052805291130213231.64) =='27052805291130212352.000000'
0

Maybe you should try using the str() method? (not tested)

df['id'] = str(df['id'])

1 Comment

This is not correct, since OP wants to convert every individual item from the collum to a string, not the entire thing

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.