Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

python - Remove scientific notation floats in a dataframe

I am receiving different series from a source. Some of those series have the values in big numbers (X billions). I then combine all the series to a dataframe with individual columns for each series.

Now, when I print the dataframe, the big numbers in the series are showed in scientific notation. Even printing the series individually shows the numbers in scientific notation.

Dataframe df (multiindex) output is:

                 Values
Item    Sub                  
A       1        1.396567e+12
B       1        2.868929e+12

I have tried this:

pd.set_option('display.float_format', lambda x: '%,.2f' % x)

This doesn't work as:

  • it converts everywhere. I only need the conversion in that specific dataframe.
  • it tries to convert all kinds of floats, and not just those in scientific. So, even if the float is 89.142, it will try to convert the format and as there's no digit to put ',' it shows an error.

Then I tried these:

df.round(2)

This only converted numeric floats to 2 decimals from existing 3 decimals. Didn't do anything to scientific values.

Then I tried:

df.astypes(floats)

Doesn't do anything visible. Output stayed the same.

How else can we change the scientific notation to normal float digits inside the dataframe. I do not want to create a new list with the converted values. The dataframe itself should show the values in normal terms.

Can you guys please help me find a solution for this?

Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try df['column'] = df['column'].astype(str) . if does not work you should change type of numbers to string before create pandas dataframe from your data


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...