From a8221ece7e9577665c67bbbf784dc421affd37fe Mon Sep 17 00:00:00 2001 From: Craig Citro Date: Tue, 15 Aug 2023 10:42:41 -0700 Subject: [PATCH] No public description PiperOrigin-RevId: 557179116 --- google/colab/data_table.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/google/colab/data_table.py b/google/colab/data_table.py index 326da549..f2d82688 100644 --- a/google/colab/data_table.py +++ b/google/colab/data_table.py @@ -28,6 +28,8 @@ from google.colab import _interactive_table_helper from google.colab import _quickchart_hint_button +from google.colab import autoviz as _autoviz +from google.colab import widgets as _widgets import IPython as _IPython from IPython import display as _display @@ -46,6 +48,7 @@ 'disable_dataframe_formatter', 'load_ipython_extension', 'unload_ipython_extension', + 'display_dataframe', ] # For details on updating gviz js, refer to: /gviz/update_data_table @@ -282,6 +285,30 @@ def _gen_js(self, dataframe): ) +def display_dataframe(df): + """Display a dataframe as a table, possibly with additional information. + + This function is *not* intended to have a stable output: over time, the + details of what is displayed will change. Currently, this also includes + summary information and a selection of automatically generated charts. + + Args: + df: a pd.DataFrame to be displayed + + Returns: + None + """ + t = _widgets.TabBar(['Data', 'Charts', 'Summary']) + with t.output_to('Data'): + _display.display(DataTable(df, include_index=False)) + with t.output_to('Charts', select=False): + _autoviz.quickchart(df) + with t.output_to('Summary', select=False): + s = df.describe(datetime_is_numeric=True, include='all').fillna('').T + _display.display(DataTable(s)) + return + + class _JavascriptModuleFormatter(_IPython.core.formatters.BaseFormatter): format_type = _traitlets.Unicode(_JAVASCRIPT_MODULE_MIME_TYPE) print_method = _traitlets.ObjectName('_repr_javascript_module_')