pd_preferences¶
- pyhelpers.settings.pd_preferences(reset=False, max_columns=100, min_rows=10, max_rows=40, precision=4, east_asian_text=False, ignore_future_warning=True, **kwargs)[source]¶
Alter parameters of some frequently-used Pandas options and settings for displaying pandas dataframes.
This function allows adjusting various display options such as maximum number of columns, maximum number of rows, decimal precision, handling of East Asian text and suppression of future warnings.
- Parameters:
reset (bool | str) – Whether to reset all settings to their defaults; defaults to
False
.max_columns (int) – Maximum number of columns to display; corresponds to
'display.max_columns'
in pandas.set_option(); defaults to100
.min_rows (int) – Minimum number of rows to display; corresponds to
'display.min_rows'
in pandas.set_option(); defaults to10
.max_rows (int) – Maximum number of rows to display; corresponds to
'display.max_rows'
in pandas.set_option(); defaults to40
.precision (int) – Number of decimal places to display; corresponds to
'display.precision'
in pandas.set_option(); defaults to4
.east_asian_text (bool) – Whether to adjust the display for East Asian text; defaults to
False
.ignore_future_warning (bool) – Whether to ignore or suppress future warnings; defaults to
True
.kwargs – [Optional] Additional parameters for the function pandas.set_option().
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 to2
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
.