From b95e721341a312ade95643b9886e17f7abb63a4d Mon Sep 17 00:00:00 2001 From: William Granados Date: Thu, 12 Mar 2020 14:07:19 -0400 Subject: [PATCH 01/13] ENH: implemented addtionally functionality of formatters_col in to_latex --- pandas/core/generic.py | 9 +++++++++ pandas/tests/io/formats/test_to_latex.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f7eb79a4f1c78..d692945fe0b45 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2762,6 +2762,7 @@ def to_latex( index=True, na_rep="NaN", formatters=None, + formatters_col=None, float_format=None, sparsify=None, index_names=True, @@ -2809,6 +2810,10 @@ def to_latex( Formatter functions to apply to columns' elements by position or name. The result of each function must be a unicode string. List must be of length equal to the number of columns. + formatter_col: list of str, optional + Formatter elements. The result of each function must be a unicode string. + List must be of length equal to the number. This applies the changes in the original + order of the columns. float_format : one-parameter function or str, optional, default None Formatter for floating point numbers. For example ``float_format="%%.2f"`` and ``float_format="{:0.2f}".format`` will @@ -2897,6 +2902,10 @@ def to_latex( if multirow is None: multirow = config.get_option("display.latex.multirow") + # formatters is a list + if formatters_col: + formatters = [lambda x: style % x for style in formatters_col] + formatter = DataFrameFormatter( self, columns=columns, diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index c2fbc59b8f482..66ecf7304d3ea 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -133,6 +133,23 @@ def test_to_latex_with_formatters(self): index: 2 & 2016-03 & [ 3.0] & 0x3 & -False- \\ \bottomrule \end{tabular} +""" + assert result == expected + + def test_to_latex_with_formatters_col(self): + data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] + df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + + result = df.to_latex(formatters_col=["%1i", "%1.1f", "%1.3f"]) + expected = r"""\begin{tabular}{lrrr} +\toprule +{} & a & b & c \\ +\midrule +foo & 1.000 & 2.000 & 3.000 \\ +bar & 4.000 & 5.000 & 6.000 \\ +foobar & 7.000 & 8.000 & 9.001 \\ +\bottomrule +\end{tabular} """ assert result == expected From dbce558e957493ad010b66d7ecc1ef85b052a007 Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 16 Mar 2020 12:16:44 -0400 Subject: [PATCH 02/13] formatting and code refactor --- pandas/core/generic.py | 15 ++++++++------- pandas/tests/io/formats/test_to_latex.py | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d692945fe0b45..08e245db765c0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2762,7 +2762,6 @@ def to_latex( index=True, na_rep="NaN", formatters=None, - formatters_col=None, float_format=None, sparsify=None, index_names=True, @@ -2777,6 +2776,7 @@ def to_latex( multirow=None, caption=None, label=None, + formatters_col=None, ): r""" Render object to a LaTeX tabular, longtable, or nested table/tabular. @@ -2810,10 +2810,6 @@ def to_latex( Formatter functions to apply to columns' elements by position or name. The result of each function must be a unicode string. List must be of length equal to the number of columns. - formatter_col: list of str, optional - Formatter elements. The result of each function must be a unicode string. - List must be of length equal to the number. This applies the changes in the original - order of the columns. float_format : one-parameter function or str, optional, default None Formatter for floating point numbers. For example ``float_format="%%.2f"`` and ``float_format="{:0.2f}".format`` will @@ -2866,6 +2862,11 @@ def to_latex( This is used with ``\ref{}`` in the main ``.tex`` file. .. versionadded:: 1.0.0 + formatters_col: list of str, optional, default None + Formatter elements. The result of each function must be a unicode string. + List must be of length equal to the number. + This applies the changes in the original order of the columns. + %(returns)s See Also -------- @@ -2903,8 +2904,8 @@ def to_latex( multirow = config.get_option("display.latex.multirow") # formatters is a list - if formatters_col: - formatters = [lambda x: style % x for style in formatters_col] + if formatters_col and type(formatters_col) == list: + formatters = [lambda x: f"{style}{x}" for style in formatters_col] formatter = DataFrameFormatter( self, diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 66ecf7304d3ea..5fb82b269c83f 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -137,6 +137,7 @@ def test_to_latex_with_formatters(self): assert result == expected def test_to_latex_with_formatters_col(self): + # GH: 26278 data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) From ac68757dc6dc5c2d06c85db8a4ae369c1af9001f Mon Sep 17 00:00:00 2001 From: William Granados Date: Sat, 23 May 2020 02:17:12 -0400 Subject: [PATCH 03/13] added ValueError for incorrect usage of formatters_col --- pandas/core/generic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 08e245db765c0..53358cf1c23d7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2903,9 +2903,11 @@ def to_latex( if multirow is None: multirow = config.get_option("display.latex.multirow") - # formatters is a list - if formatters_col and type(formatters_col) == list: - formatters = [lambda x: f"{style}{x}" for style in formatters_col] + if formatters_col: + if is_list_like(formatters_col): + formatters = [lambda x: style % x for style in formatters_col] + else: + raise ValueError formatter = DataFrameFormatter( self, From a8afd72b3d9d58d58c3dd3a96c8f935ebb17d484 Mon Sep 17 00:00:00 2001 From: William Granados Date: Sat, 23 May 2020 16:45:11 -0400 Subject: [PATCH 04/13] renamed kwarg param for consistency --- pandas/core/generic.py | 17 +++++++---------- pandas/tests/io/formats/test_to_latex.py | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 53358cf1c23d7..6811d6931eaef 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2776,7 +2776,7 @@ def to_latex( multirow=None, caption=None, label=None, - formatters_col=None, + multifloat_format=None, ): r""" Render object to a LaTeX tabular, longtable, or nested table/tabular. @@ -2854,17 +2854,14 @@ def to_latex( from the pandas config module. caption : str, optional The LaTeX caption to be placed inside ``\caption{}`` in the output. - .. versionadded:: 1.0.0 - label : str, optional The LaTeX label to be placed inside ``\label{}`` in the output. This is used with ``\ref{}`` in the main ``.tex`` file. - .. versionadded:: 1.0.0 - formatters_col: list of str, optional, default None - Formatter elements. The result of each function must be a unicode string. - List must be of length equal to the number. + multifloat_format: list of str, default None, optional + Formatting floats by columns, similar to `float_format`. + The result of each function must be a unicode string. This applies the changes in the original order of the columns. %(returns)s @@ -2903,9 +2900,9 @@ def to_latex( if multirow is None: multirow = config.get_option("display.latex.multirow") - if formatters_col: - if is_list_like(formatters_col): - formatters = [lambda x: style % x for style in formatters_col] + if multifloat_format: + if is_list_like(multifloat_format): + formatters = [lambda x: style % x for style in multifloat_format] else: raise ValueError diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 5fb82b269c83f..b0934a7eb03bb 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -136,12 +136,12 @@ def test_to_latex_with_formatters(self): """ assert result == expected - def test_to_latex_with_formatters_col(self): + def test_to_latex_with_multifloat_format(self): # GH: 26278 data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(formatters_col=["%1i", "%1.1f", "%1.3f"]) + result = df.to_latex(multifloat_format=["%1i", "%1.1f", "%1.3f"]) expected = r"""\begin{tabular}{lrrr} \toprule {} & a & b & c \\ From 7e0ef760cfe25c5343683e41b4d290c9ec31cd7c Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 29 Jun 2020 16:39:24 -0400 Subject: [PATCH 05/13] change api usage and fstring usage --- pandas/core/generic.py | 19 ++++++++----------- pandas/tests/io/formats/test_to_latex.py | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6811d6931eaef..cc69246bf8447 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2776,7 +2776,6 @@ def to_latex( multirow=None, caption=None, label=None, - multifloat_format=None, ): r""" Render object to a LaTeX tabular, longtable, or nested table/tabular. @@ -2806,7 +2805,7 @@ def to_latex( Write row names (index). na_rep : str, default 'NaN' Missing data representation. - formatters : list of functions or dict of {str: function}, optional + formatters : list of functions/str or dict of {str: function}, optional Formatter functions to apply to columns' elements by position or name. The result of each function must be a unicode string. List must be of length equal to the number of columns. @@ -2859,10 +2858,6 @@ def to_latex( The LaTeX label to be placed inside ``\label{}`` in the output. This is used with ``\ref{}`` in the main ``.tex`` file. .. versionadded:: 1.0.0 - multifloat_format: list of str, default None, optional - Formatting floats by columns, similar to `float_format`. - The result of each function must be a unicode string. - This applies the changes in the original order of the columns. %(returns)s See Also @@ -2900,11 +2895,13 @@ def to_latex( if multirow is None: multirow = config.get_option("display.latex.multirow") - if multifloat_format: - if is_list_like(multifloat_format): - formatters = [lambda x: style % x for style in multifloat_format] - else: - raise ValueError + if is_list_like(formatters) and not isinstance(formatters, dict): + formatter_elems_is_str = all(isinstance(elem, str) for elem in formatters) + formatter_elems_is_lambda = all(callable(elem) for elem in formatters) + if formatter_elems_is_str: + formatters = [ lambda x: "{0:{1}}".format(x, style) for style in formatters] + elif not formatter_elems_is_lambda: + raise ValueError("Formatters elements should be strings") formatter = DataFrameFormatter( self, diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index b0934a7eb03bb..a4030803a6d2f 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -136,12 +136,12 @@ def test_to_latex_with_formatters(self): """ assert result == expected - def test_to_latex_with_multifloat_format(self): + def test_to_latex_with_float_format_list(self): # GH: 26278 data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(multifloat_format=["%1i", "%1.1f", "%1.3f"]) + result = df.to_latex(formatters=["1.1f", "1.2f", "1.3f"]) expected = r"""\begin{tabular}{lrrr} \toprule {} & a & b & c \\ @@ -151,6 +151,24 @@ def test_to_latex_with_multifloat_format(self): foobar & 7.000 & 8.000 & 9.001 \\ \bottomrule \end{tabular} +""" + assert result == expected + + def test_to_latex_with_float_format_list(self): + # GH: 26278 + data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] + df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + + result = df.to_latex(formatters=["d", ".1f", ".3f"]) + expected = r"""\begin{tabular}{lrrr} +\toprule +{} & a & b & c \\ +\midrule +foo & 1 & 2.0 & 3.000 \\ +bar & 4 & 5.0 & 6.000 \\ +foobar & 7 & 8.0 & 9.001 \\ +\bottomrule +\end{tabular} """ assert result == expected From 2dce2e2326e978acdd60cfff29d73c008d2187e6 Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 29 Jun 2020 17:14:48 -0400 Subject: [PATCH 06/13] fixed lambda functionality and updated test --- pandas/core/generic.py | 2 +- pandas/tests/io/formats/test_to_latex.py | 28 +++++------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cc69246bf8447..2a26087c1100b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2899,7 +2899,7 @@ def to_latex( formatter_elems_is_str = all(isinstance(elem, str) for elem in formatters) formatter_elems_is_lambda = all(callable(elem) for elem in formatters) if formatter_elems_is_str: - formatters = [ lambda x: "{0:{1}}".format(x, style) for style in formatters] + formatters = [ (lambda style: lambda x: "{0:{1}}".format(x, style))(style) for style in formatters ] elif not formatter_elems_is_lambda: raise ValueError("Formatters elements should be strings") diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index a4030803a6d2f..1650ed98b69a3 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -141,32 +141,14 @@ def test_to_latex_with_float_format_list(self): data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(formatters=["1.1f", "1.2f", "1.3f"]) + result = df.to_latex(formatters=["d", ".2f", ".3f"]) expected = r"""\begin{tabular}{lrrr} \toprule -{} & a & b & c \\ +{} & a & b & c \\ \midrule -foo & 1.000 & 2.000 & 3.000 \\ -bar & 4.000 & 5.000 & 6.000 \\ -foobar & 7.000 & 8.000 & 9.001 \\ -\bottomrule -\end{tabular} -""" - assert result == expected - - def test_to_latex_with_float_format_list(self): - # GH: 26278 - data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] - df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - - result = df.to_latex(formatters=["d", ".1f", ".3f"]) - expected = r"""\begin{tabular}{lrrr} -\toprule -{} & a & b & c \\ -\midrule -foo & 1 & 2.0 & 3.000 \\ -bar & 4 & 5.0 & 6.000 \\ -foobar & 7 & 8.0 & 9.001 \\ +foo & 1 & 2.00 & 3.000 \\ +bar & 4 & 5.00 & 6.000 \\ +foobar & 7 & 8.00 & 9.001 \\ \bottomrule \end{tabular} """ From ac2f774ff281e9e1f5edec5ebd32271600a6e55b Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 29 Jun 2020 17:20:21 -0400 Subject: [PATCH 07/13] formatting change --- pandas/core/generic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2a26087c1100b..a01bb3d801855 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2899,7 +2899,10 @@ def to_latex( formatter_elems_is_str = all(isinstance(elem, str) for elem in formatters) formatter_elems_is_lambda = all(callable(elem) for elem in formatters) if formatter_elems_is_str: - formatters = [ (lambda style: lambda x: "{0:{1}}".format(x, style))(style) for style in formatters ] + formatters = [ + (lambda style: lambda x: "{0:{1}}".format(x, style))(style) + for style in formatters + ] elif not formatter_elems_is_lambda: raise ValueError("Formatters elements should be strings") From 3656b23df9b616697ddc3f3824057e5ef8552a66 Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 29 Jun 2020 19:02:11 -0400 Subject: [PATCH 08/13] update docs --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a01bb3d801855..6d5f8f36cb0f9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2853,12 +2853,14 @@ def to_latex( from the pandas config module. caption : str, optional The LaTeX caption to be placed inside ``\caption{}`` in the output. + .. versionadded:: 1.0.0 + label : str, optional The LaTeX label to be placed inside ``\label{}`` in the output. This is used with ``\ref{}`` in the main ``.tex`` file. - .. versionadded:: 1.0.0 + .. versionadded:: 1.0.0 %(returns)s See Also -------- From 7f96b48041a8411b5df1c32a1ff587ebadff58f3 Mon Sep 17 00:00:00 2001 From: William Granados Date: Sun, 30 Aug 2020 16:58:56 -0400 Subject: [PATCH 09/13] added what's new entry and made to_latex more flexible --- doc/source/whatsnew/v1.2.0.rst | 10 ++++++++++ pandas/core/generic.py | 15 ++++++++++----- pandas/tests/io/formats/test_to_latex.py | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 doc/source/whatsnew/v1.2.0.rst diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst new file mode 100644 index 0000000000000..c789f64b79d2b --- /dev/null +++ b/doc/source/whatsnew/v1.2.0.rst @@ -0,0 +1,10 @@ +ToLatex +^^^^^^^ + +- Can now substitute simple fstrings in place of callable functions in to_latex + +.. ipython:: python + + data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] + df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) \ No newline at end of file diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6d5f8f36cb0f9..6c48ff98bc142 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2898,15 +2898,20 @@ def to_latex( multirow = config.get_option("display.latex.multirow") if is_list_like(formatters) and not isinstance(formatters, dict): - formatter_elems_is_str = all(isinstance(elem, str) for elem in formatters) - formatter_elems_is_lambda = all(callable(elem) for elem in formatters) - if formatter_elems_is_str: + formatter_elems_type = all( + isinstance(elem, str) or callable(elem) for elem in formatters + ) + if formatter_elems_type: formatters = [ (lambda style: lambda x: "{0:{1}}".format(x, style))(style) + if isinstance(style, str) + else style for style in formatters ] - elif not formatter_elems_is_lambda: - raise ValueError("Formatters elements should be strings") + else: + raise ValueError( + "Formatters elements should be f-strings or callable functions" + ) formatter = DataFrameFormatter( self, diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 1650ed98b69a3..73d544c0f5580 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -141,7 +141,7 @@ def test_to_latex_with_float_format_list(self): data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(formatters=["d", ".2f", ".3f"]) + result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) expected = r"""\begin{tabular}{lrrr} \toprule {} & a & b & c \\ From 4d5483402360a7a4a1cbc23b811d6697d9f03a2b Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 31 Aug 2020 00:39:17 -0400 Subject: [PATCH 10/13] fix doc build error --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 532217a0d22ec..021c4850642a8 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -285,7 +285,7 @@ ToLatex .. ipython:: python data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] - df = DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) From 969c0875986d9264b351e39fadff7b1adfa145a1 Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 31 Aug 2020 01:06:22 -0400 Subject: [PATCH 11/13] change whats new line length --- doc/source/whatsnew/v1.2.0.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 021c4850642a8..7e8a0369fc818 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -284,9 +284,9 @@ ToLatex .. ipython:: python - data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] - df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) + data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] + df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) Other From bc6f2cd43cc08a60e4916fcf404caa3935c34d1c Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 31 Aug 2020 01:47:53 -0400 Subject: [PATCH 12/13] spacing linting --- doc/source/whatsnew/v1.2.0.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 7e8a0369fc818..a43f3ec4b96f6 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -284,9 +284,9 @@ ToLatex .. ipython:: python - data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] - df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) - result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) + data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] + df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"]) Other From dd76b5bc01df20ebed47fdb6f17a0261e039cc2b Mon Sep 17 00:00:00 2001 From: William Granados Date: Mon, 5 Oct 2020 21:10:59 -0400 Subject: [PATCH 13/13] changed docs formatting --- doc/source/whatsnew/v1.2.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index a43f3ec4b96f6..8e9d873a3f643 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -285,7 +285,8 @@ ToLatex .. ipython:: python data = [[1, 2, 3], [4, 5, 6], [7, 8, 9.001]] - df = pd.DataFrame(data, columns=["a", "b", "c"], index=["foo", "bar", "foobar"]) + df = pd.DataFrame(data, columns=["a", "b", "c"], + index=["foo", "bar", "foobar"]) result = df.to_latex(formatters=["d", ".2f", lambda x: f"{x:.3f}"])