Suppress Scientific Notation in Pandas Groupby Aggregation Results
When performing groupby operations in pandas, large numerical results may be displayed in scientific notation. This can be undesirable for readability or subsequent processing.
To modify the formatting, use pd.set_option('display.float_format') to define a custom string converter. For example:
<code class="python">import pandas as pd pd.set_option('display.float_format', lambda x: '%.3f' % x)</code>
This will display floating-point numbers with three decimal places. Note that this is a global setting and will affect all floating-point numbers displayed in pandas.
While converting numbers to strings for aesthetic purposes is generally discouraged, it can be achieved using apply() with a custom string formatting function:
<code class="python">df['result'].apply(lambda x: '%.3f' % x)</code>
This will apply the specified string formatting to each element in the 'result' column.
The above is the detailed content of How to Suppress Scientific Notation in Pandas Groupby Aggregation Results?. For more information, please follow other related articles on the PHP Chinese website!