简体   繁体   中英

Converting float to string without scientific notation

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?

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)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM