Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...