From a2cd04536ef5326aa007b91b9c9afb17e1942314 Mon Sep 17 00:00:00 2001 From: Goutham Anand Date: Fri, 24 Oct 2025 17:49:36 -0700 Subject: [PATCH] Added example for pandas.DataFrame.to_html #44945 --- pandas/core/frame.py | 87 +++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d4ff1bc4f35ac..e4dd1a600fccf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3293,28 +3293,71 @@ def to_html( Examples -------- >>> df = pd.DataFrame(data={"col1": [1, 2], "col2": [4, 3]}) - >>> html_string = ''' - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ...
col1col2
014
123
''' - >>> assert html_string == df.to_html() + >>> html_string = df.to_html() + >>> print(html_string) + + + + + + + + + + + + + + + + + + + + +
col1col2
014
123
+ + HTML output + + +----+-----+-----+ + | |col1 |col2 | + +====+=====+=====+ + |0 |1 |4 | + +----+-----+-----+ + |1 |2 |3 | + +----+-----+-----+ + + >>> df = pd.DataFrame(data={"col1": [1, 2], "col2": [4, 3]}) + >>> html_string = df.to_html(index=False) + >>> print(html_string) + + + + + + + + + + + + + + + + + +
col1col2
14
23
+ + HTML output + + +-----+-----+ + |col1 |col2 | + +=====+=====+ + |1 |4 | + +-----+-----+ + |2 |3 | + +-----+-----+ """ if justify is not None and justify not in fmt.VALID_JUSTIFY_PARAMETERS: raise ValueError("Invalid value for justify parameter")