pd_preferences

pyhelpers.settings.pd_preferences(reset=False, max_columns=100, max_rows=20, precision=4, east_asian_text=False, ignore_future_warning=True)[source]

Alter parameters of some frequently-used Pandas options and settings for displaying data frame.

Parameters:
  • reset (bool | str) – whether to reset all to default settings, defaults to False

  • max_columns (int) – maximum number of columns, which corresponds to 'display.max_columns' for pandas.set_option(), defaults to 100

  • max_rows (int) – maximum number of rows, which corresponds to 'display.max_rows' for pandas.set_option(), defaults to 20

  • precision (int) – number of decimal places, which corresponds to 'display.precision' for pandas.set_option(), defaults to 4

  • east_asian_text (bool) – whether to adjust the display for east asian texts, defaults to False

  • ignore_future_warning (bool) – whether to ignore/suppress future warnings, defaults to True

Examples:

>>> import numpy as np
>>> import pandas as pd

>>> np.random.seed(0)

>>> random_array = np.random.rand(100, 100)

>>> data_frame = pd.DataFrame(random_array)
>>> data_frame
          0         1         2   ...        97        98        99
0   0.548814  0.715189  0.602763  ...  0.020108  0.828940  0.004695
1   0.677817  0.270008  0.735194  ...  0.254356  0.058029  0.434417
2   0.311796  0.696343  0.377752  ...  0.862192  0.972919  0.960835
3   0.906555  0.774047  0.333145  ...  0.356707  0.016329  0.185232
4   0.401260  0.929291  0.099615  ...  0.401714  0.248413  0.505866
..       ...       ...       ...  ...       ...       ...       ...
95  0.029929  0.985128  0.094747  ...  0.369907  0.910011  0.142890
96  0.616935  0.202908  0.288809  ...  0.215006  0.143577  0.933162
97  0.891112  0.268674  0.840285  ...  0.573680  0.737291  0.225198
98  0.269698  0.738825  0.807145  ...  0.948368  0.881307  0.141933
99  0.884982  0.197014  0.568613  ...  0.758430  0.023787  0.813575
[100 rows x 100 columns]

Limit to display of at most 6 columns and round the numbers to 2 decimal places:

>>> from pyhelpers.settings import pd_preferences

>>> pd_preferences(max_columns=6, precision=2)

>>> data_frame
     0    1    2   ...   97   98   99
0  0.55 0.72 0.60  ... 0.02 0.83 0.00
1  0.68 0.27 0.74  ... 0.25 0.06 0.43
2  0.31 0.70 0.38  ... 0.86 0.97 0.96
3  0.91 0.77 0.33  ... 0.36 0.02 0.19
4  0.40 0.93 0.10  ... 0.40 0.25 0.51
..  ...  ...  ...  ...  ...  ...  ...
95 0.03 0.99 0.09  ... 0.37 0.91 0.14
96 0.62 0.20 0.29  ... 0.22 0.14 0.93
97 0.89 0.27 0.84  ... 0.57 0.74 0.23
98 0.27 0.74 0.81  ... 0.95 0.88 0.14
99 0.88 0.20 0.57  ... 0.76 0.02 0.81
[100 rows x 100 columns]

Reset to default settings:

>>> pd_preferences(reset=True)

>>> data_frame
          0         1         2   ...        97        98        99
0   0.548814  0.715189  0.602763  ...  0.020108  0.828940  0.004695
1   0.677817  0.270008  0.735194  ...  0.254356  0.058029  0.434417
2   0.311796  0.696343  0.377752  ...  0.862192  0.972919  0.960835
3   0.906555  0.774047  0.333145  ...  0.356707  0.016329  0.185232
4   0.401260  0.929291  0.099615  ...  0.401714  0.248413  0.505866
..       ...       ...       ...  ...       ...       ...       ...
95  0.029929  0.985128  0.094747  ...  0.369907  0.910011  0.142890
96  0.616935  0.202908  0.288809  ...  0.215006  0.143577  0.933162
97  0.891112  0.268674  0.840285  ...  0.573680  0.737291  0.225198
98  0.269698  0.738825  0.807145  ...  0.948368  0.881307  0.141933
99  0.884982  0.197014  0.568613  ...  0.758430  0.023787  0.813575
[100 rows x 100 columns]

Note

  • Default values of all available options can be checked by running pandas.describe_option() or pandas._config.config._registered_options