Home > Article > Backend Development > How to Format Aggregation Results in Pandas Without Scientific Notation?
When performing groupby operations in Pandas, large numbers can be represented in scientific notation. To format these numbers and suppress scientific notation, follow these steps:
Option 1: Customize String Converter
You can specify a custom string converter using the pd.set_option() function. The following code sets the format to display three decimal places:
<code class="python">pd.set_option('display.float_format', lambda x: '%.3f' % x)</code>
Option 2: Convert to String and Format
If you prefer to convert the numbers to strings before formatting, you can use the astype() method followed by the apply() method:
<code class="python">sum_sales_dept.astype(str).apply(lambda x: '%.3f' % float(x))</code>
These options allow you to format aggregation results in Pandas and display large numbers without scientific notation. Note that converting numbers to strings can impact performance and may not be the preferred approach in all cases.
The above is the detailed content of How to Format Aggregation Results in Pandas Without Scientific Notation?. For more information, please follow other related articles on the PHP Chinese website!