diff --git a/README.md b/README.md index fa3dc82..d47d056 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,12 @@ # Greater Tables -Creating presentation quality tables from pandas dataframes is -frustrating. It is hard to left-align text and right-align numbers using -pandas `display` or `df.to_html`. The `great_tables` package does a -really nice job with pandas and polars dataframes but does not support -indexes or TeX output. +Creating presentation quality tables from pandas dataframes is frustrating. It is hard to left-align text and right-align numbers using pandas `display` or `df.to_html`. The `great_tables` package does a really nice job with pandas and polars dataframes but does not support indexes or TeX output. -This package is provides consistent HTML and TeX table output with -flexible type-based formatting, and table rules. Its main class `GT` can -be subclassed to set appropriate defaults for your project. +This package provides consistent HTML and TeX table output with flexible type-based formatting, and table rules. Neither output relies on the pandas `to_html` or `to_latex` functions. TeX output uses Tikz tables for very tight control over layout and grid lines. The package is designed for use in Jupyter Lab notebooks Quarto documents. -The project is currently in **beta** status. +Usage: the main class `GT` should be subclassed to set appropriate defaults for your project. `sGT` provides an example. + +The project is currently in **beta** status. HTML output is better developed than TeX. ## The Name @@ -36,7 +32,7 @@ import pandas as pd import numpy as np from greater_tables import sGT level_1 = ["Group A", "Group A", "Group B", "Group B", 'Group C'] -level_2 = ['Sub 1', 'Sub 2', 'Sub 2', 'Sub 1', 'Sub 1'] +level_2 = ['Sub 1', 'Sub 2', 'Sub 2', 'Sub 3', 'Sub 3'] multi_index = pd.MultiIndex.from_arrays([level_1, level_2]) @@ -49,167 +45,25 @@ hard = pd.DataFrame( 'b': 10. ** np.linspace(-9, 9, 5), 'c': np.linspace(601, 4000, 5), 'd': pd.date_range(start=start, end=end, periods=5), -'e': 'once upon a time, lived happily ever after, not in Kansas anymore, neutrinos are hard to detect, risk is hard to define'.split(',') +'e': 'once upon a time, risk is hard to define, not in Kansas anymore, neutrinos are hard to detect, $\\int_\\infty^\\infty e^{-x^2/2}dx$ is a hard integral'.split(',') }).set_index('x') hard.columns = multi_index -print(sGT(hard, 'A hard table.').html) +sGT(hard, 'A hard table.') ``` - +![HTML output.](img/hard-html.png){width=66%} - +![TeX output.](img/hard-tex.png){width=66%} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-A hard table. -
- -Group A - -Group B - -Group C -
-x - -Sub 1 - -Sub 2 - -Sub 2 - -Sub 1 - -Sub 1 -
-2020 - -100 - -1.000n - -601.00 - -2025-03-12 - -once upon a time -
-2021 - -105 - -31.623u - -1,450.75 - -2025-05-24 - -lived happily ever after -
-2022 - -2,000 - -1.000 - -2,300.50 - -2025-08-06 - -not in Kansas anymore -
-2023 - -2,025 - -31.623k - -3,150.25 - -2025-10-18 - -neutrinos are hard to detect -
-2024 - -100,000 - -1.000G - -4,000.00 - -2025-12-31 - -risk is hard to define -
- - -Note the following features: +The output illustrates: +- Quarto or Jupyter automatically the class's `_repr_html_` method (or + `_repr_latex_` for pdf/TeX/Beamer output), providing seamless + integration across different output formats. - Text is left-aligned, numbers are right-aligned. - The index is displayed, was detected as likely years, and formatted without a comma separator. -- The first column of integers does have a comma separator. +- The first column of integers does have a comma thousands separator. - The second column of floats spans several orders of magnitude and is formatted using Engineering format, n for nano through G for giga. - The third column of floats is formatted with a comma separator and diff --git a/README.qmd b/README.qmd index 29b9f66..0048e96 100644 --- a/README.qmd +++ b/README.qmd @@ -18,7 +18,7 @@ jupyter: Creating presentation quality tables from pandas dataframes is frustrating. It is hard to left-align text and right-align numbers using pandas `display` or `df.to_html`. The `great_tables` package does a really nice job with pandas and polars dataframes but does not support indexes or TeX output. -This package is provides consistent HTML and TeX table output with flexible type-based formatting, and table rules. Its main class `GT` can be subclassed to set appropriate defaults for your project. +This package provides consistent HTML and TeX table output with flexible type-based formatting, and table rules. Its main class `GT` can be subclassed to set appropriate defaults for your project. It is designed for use in Jupyter Lab notebooks Quarto documents. The project is currently in **beta** status. @@ -43,7 +43,7 @@ import pandas as pd import numpy as np from greater_tables import sGT level_1 = ["Group A", "Group A", "Group B", "Group B", 'Group C'] -level_2 = ['Sub 1', 'Sub 2', 'Sub 2', 'Sub 1', 'Sub 1'] +level_2 = ['Sub 1', 'Sub 2', 'Sub 2', 'Sub 3', 'Sub 3'] multi_index = pd.MultiIndex.from_arrays([level_1, level_2]) @@ -56,17 +56,22 @@ hard = pd.DataFrame( 'b': 10. ** np.linspace(-9, 9, 5), 'c': np.linspace(601, 4000, 5), 'd': pd.date_range(start=start, end=end, periods=5), -'e': 'once upon a time, lived happily ever after, not in Kansas anymore, neutrinos are hard to detect, risk is hard to define'.split(',') +'e': 'once upon a time, risk is hard to define, not in Kansas anymore, neutrinos are hard to detect, $\\int_\\infty^\\infty e^{-x^2/2}dx$ is a hard integral'.split(',') }).set_index('x') hard.columns = multi_index -print(sGT(hard, 'A hard table.').html) +sGT(hard, 'A hard table.') ``` -Note the following features: +![HTML output](hard_table_html.png) +![TeX output](hard_table_tex.png) + +The output illustrates: + +* Quarto or Jupyter automatically the class's `_repr_html_` method (or `_repr_latex_` for pdf/TeX/Beamer output), providing seamless integration across different output formats. * Text is left-aligned, numbers are right-aligned. * The index is displayed, was detected as likely years, and formatted without a comma separator. -* The first column of integers does have a comma separator. +* The first column of integers does have a comma thousands separator. * The second column of floats spans several orders of magnitude and is formatted using Engineering format, n for nano through G for giga. * The third column of floats is formatted with a comma separator and two decimals, based on the average absolute value. * The fourth column of date times is formatted as ISO standard dates (not date times). diff --git a/img/hard-html.png b/img/hard-html.png new file mode 100644 index 0000000..60554e4 Binary files /dev/null and b/img/hard-html.png differ diff --git a/img/hard-tex.png b/img/hard-tex.png new file mode 100644 index 0000000..ad8dedc Binary files /dev/null and b/img/hard-tex.png differ