diff --git a/doc/source/basics.rst b/doc/source/basics.rst index 0e449cb35eaaa..7d6efdb85b94a 100644 --- a/doc/source/basics.rst +++ b/doc/source/basics.rst @@ -1666,3 +1666,35 @@ columns of DataFrame objects are shown by default. If ``max_columns`` is set to 0 (the default, in fact), the library will attempt to fit the DataFrame's string representation into the current terminal width, and defaulting to the summary view otherwise. + +The visualization of a dataframe can be controled directly with two +options - `large_repr` and `info_verbose`. Depending on the size of +the DataFrame it might be more convenient to print a summary +representation only. + +.. ipython:: python + + df_lrge = DataFrame(columns=['a','b','c'], + index=DatetimeIndex(start='19900101',end='20000101',freq='BM')) + +The default display for a DataFrame is 'truncate'. This prints all +elements of the df up to max_rows/max_columns. + +.. ipython:: python + + with option_context("display.large_repr",'truncate'): + print df_lrge + +To get a more concise representation of the df + +.. ipython:: python + + with option_context("display.large_repr",'info'): + print df_lrge + +Further reduce summary view to one line for all columns + +.. ipython:: python + + with option_context("display.large_repr",'info',"display.info_verbose",False): + print df_lrge diff --git a/doc/source/faq.rst b/doc/source/faq.rst index 6460662553d6b..f311da9cfb402 100644 --- a/doc/source/faq.rst +++ b/doc/source/faq.rst @@ -45,6 +45,11 @@ As of 0.13, these are the relevant options, all under the `display` namespace, - large_repr (default 'truncate'): when a :class:`~pandas.DataFrame` exceeds max_columns or max_rows, it can be displayed either as a truncated table or, with this set to 'info', as a short summary view. +- info_verbose (default True): When large_repr is set to 'info', the + index of a :class:`~pandas.DataFrame` will be displayed as a short + summary, while columns are still listed individually. When + 'info_verbose' is set to False, the columns will be displayed in a + short summary view also. - max_columns (default 20): max dataframe columns to display. - max_rows (default 60): max dataframe rows display. - show_dimensions (default True): controls the display of the row/col counts footer. diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 9533c0921e1e3..be8c7ec897e37 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -183,8 +183,17 @@ df.info() (the behaviour in earlier versions of pandas). """ +pc_info_verbose_doc = """ +: boolean + + Relevant when `large_repr` set to `info`. Dictates whether a df + will be displayed as df.info(verbose=True) or + df.info(verbose=False). When `False`, columns are displayed in a + summary line, instead of listing all columns. +""" + pc_mpl_style_doc = """ -: bool +: boolean Setting this to 'default' will modify the rcParams used by matplotlib to give plots a more pleasing visual style by default. @@ -230,6 +239,8 @@ def mpl_style_cb(key): validator=is_instance_factory([type(None), int])) cf.register_option('large_repr', 'truncate', pc_large_repr_doc, validator=is_one_of_factory(['truncate', 'info'])) + cf.register_option('info_verbose', True, pc_info_verbose_doc, + validator=is_bool) cf.register_option('max_info_columns', 100, pc_max_info_cols_doc, validator=is_int) cf.register_option('colheader_justify', 'right', colheader_justify_doc, diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2f8c70024a1e7..662e74aa67a7e 100755 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1381,13 +1381,13 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None, if buf is None: return formatter.buf.getvalue() - def info(self, verbose=True, buf=None, max_cols=None): + def info(self, verbose=None, buf=None, max_cols=None): """ Concise summary of a DataFrame. Parameters ---------- - verbose : boolean, default True + verbose : boolean, default None If False, don't print column count summary buf : writable buffer, defaults to sys.stdout max_cols : int, default None @@ -1395,6 +1395,9 @@ def info(self, verbose=True, buf=None, max_cols=None): """ from pandas.core.format import _put_lines + if verbose is None: + verbose = get_option("display.info_verbose") + if buf is None: # pragma: no cover buf = sys.stdout