mirror of
https://github.com/wassname/greater_tables_project.git
synced 2026-07-28 11:20:33 +08:00
248 KiB
248 KiB
In [40]:
#| echo: true
#| label: setup
from IPython.display import HTML, display
import matplotlib as mpl
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import greater_tables as gter
import greater_tables.utilities as gtu
from greater_tables import GT, sGT
gter.logger.setLevel(gter.logging.WARNING)In [ ]:
In [61]:
#| label: tbl-hard-rules
#| tbl-cap: Default display output (Quarto generated caption)
level_1 = ["A", "A", "B", "B", 'C']
level_2 = ['Int', 'Float', 'Float', 3, 'Longer Text']
multi_index = pd.MultiIndex.from_arrays([level_1, level_2],
names=["Level 1", "Level 2"])
start = pd.Timestamp.today().normalize() # Today's date, normalized to midnight
end = pd.Timestamp(f"{start.year}-12-31") # End of the year
hard = pd.DataFrame(
{'years!': np.arange(2000, 2025, dtype=int),
'a': np.array(np.round(np.linspace(-100000, 100000, 25), 0), dtype=int),
'b': 9.3 ** np.linspace(-12, 12, 25),
'c': np.linspace(-1601, 4000, 25),
'd': pd.date_range(start=start, end=end, periods=25),
'e': ('once upon a time, risk is hard to define, not in Kansas anymore, '
'neutrinos are hard to detect, '
'Adam Smith is the father of economics'.split(',') * 5)
}).set_index('years!')
# hard = hard.head()
hard.columns = multi_index
hardOut [61]:
| Level 1 | A | B | C | ||
|---|---|---|---|---|---|
| Level 2 | Int | Float | Float | 3 | Longer Text |
| years! | |||||
| 2000 | -100000 | 2.388937e-12 | -1601.000 | 2025-03-14 00:00:00 | once upon a time |
| 2001 | -91667 | 2.221711e-11 | -1367.625 | 2025-03-26 04:00:00 | risk is hard to define |
| 2002 | -83333 | 2.066191e-10 | -1134.250 | 2025-04-07 08:00:00 | not in Kansas anymore |
| 2003 | -75000 | 1.921558e-09 | -900.875 | 2025-04-19 12:00:00 | neutrinos are hard to detect |
| 2004 | -66667 | 1.787049e-08 | -667.500 | 2025-05-01 16:00:00 | Adam Smith is the father of economics |
| 2005 | -58333 | 1.661955e-07 | -434.125 | 2025-05-13 20:00:00 | once upon a time |
| 2006 | -50000 | 1.545619e-06 | -200.750 | 2025-05-26 00:00:00 | risk is hard to define |
| 2007 | -41667 | 1.437425e-05 | 32.625 | 2025-06-07 04:00:00 | not in Kansas anymore |
| 2008 | -33333 | 1.336805e-04 | 266.000 | 2025-06-19 08:00:00 | neutrinos are hard to detect |
| 2009 | -25000 | 1.243229e-03 | 499.375 | 2025-07-01 12:00:00 | Adam Smith is the father of economics |
| 2010 | -16667 | 1.156203e-02 | 732.750 | 2025-07-13 16:00:00 | once upon a time |
| 2011 | -8333 | 1.075269e-01 | 966.125 | 2025-07-25 20:00:00 | risk is hard to define |
| 2012 | 0 | 1.000000e+00 | 1199.500 | 2025-08-07 00:00:00 | not in Kansas anymore |
| 2013 | 8333 | 9.300000e+00 | 1432.875 | 2025-08-19 04:00:00 | neutrinos are hard to detect |
| 2014 | 16667 | 8.649000e+01 | 1666.250 | 2025-08-31 08:00:00 | Adam Smith is the father of economics |
| 2015 | 25000 | 8.043570e+02 | 1899.625 | 2025-09-12 12:00:00 | once upon a time |
| 2016 | 33333 | 7.480520e+03 | 2133.000 | 2025-09-24 16:00:00 | risk is hard to define |
| 2017 | 41667 | 6.956884e+04 | 2366.375 | 2025-10-06 20:00:00 | not in Kansas anymore |
| 2018 | 50000 | 6.469902e+05 | 2599.750 | 2025-10-19 00:00:00 | neutrinos are hard to detect |
| 2019 | 58333 | 6.017009e+06 | 2833.125 | 2025-10-31 04:00:00 | Adam Smith is the father of economics |
| 2020 | 66667 | 5.595818e+07 | 3066.500 | 2025-11-12 08:00:00 | once upon a time |
| 2021 | 75000 | 5.204111e+08 | 3299.875 | 2025-11-24 12:00:00 | risk is hard to define |
| 2022 | 83333 | 4.839823e+09 | 3533.250 | 2025-12-06 16:00:00 | not in Kansas anymore |
| 2023 | 91667 | 4.501035e+10 | 3766.625 | 2025-12-18 20:00:00 | neutrinos are hard to detect |
| 2024 | 100000 | 4.185963e+11 | 4000.000 | 2025-12-31 00:00:00 | Adam Smith is the father of economics |
In [65]:
#| label: tbl-hard-rules-2
#| tbl-cap: Greater Tables output (Quarto generated caption)
sGT(hard, 'A table with varied columns.')Out [65]:
| A | B | C | |||
|---|---|---|---|---|---|
| years! | Int | Float | Float | 3 | Longer Text |
| 2000 | -100,000 | 2.389p | -1,601.00 | 2025-03-14 | once upon a time |
| 2001 | -91,667 | 22.217p | -1,367.62 | 2025-03-26 | risk is hard to define |
| 2002 | -83,333 | 206.619p | -1,134.25 | 2025-04-07 | not in Kansas anymore |
| 2003 | -75,000 | 1.922n | -900.88 | 2025-04-19 | neutrinos are hard to detect |
| 2004 | -66,667 | 17.870n | -667.50 | 2025-05-01 | Adam Smith is the father of economics |
| 2005 | -58,333 | 166.196n | -434.12 | 2025-05-13 | once upon a time |
| 2006 | -50,000 | 1.546u | -200.75 | 2025-05-26 | risk is hard to define |
| 2007 | -41,667 | 14.374u | 32.62 | 2025-06-07 | not in Kansas anymore |
| 2008 | -33,333 | 133.681u | 266.00 | 2025-06-19 | neutrinos are hard to detect |
| 2009 | -25,000 | 1.243m | 499.38 | 2025-07-01 | Adam Smith is the father of economics |
| 2010 | -16,667 | 11.562m | 732.75 | 2025-07-13 | once upon a time |
| 2011 | -8,333 | 107.527m | 966.12 | 2025-07-25 | risk is hard to define |
| 2012 | 0 | 1.000 | 1,199.50 | 2025-08-07 | not in Kansas anymore |
| 2013 | 8,333 | 9.300 | 1,432.88 | 2025-08-19 | neutrinos are hard to detect |
| 2014 | 16,667 | 86.490 | 1,666.25 | 2025-08-31 | Adam Smith is the father of economics |
| 2015 | 25,000 | 804.357 | 1,899.62 | 2025-09-12 | once upon a time |
| 2016 | 33,333 | 7.481k | 2,133.00 | 2025-09-24 | risk is hard to define |
| 2017 | 41,667 | 69.569k | 2,366.38 | 2025-10-06 | not in Kansas anymore |
| 2018 | 50,000 | 646.990k | 2,599.75 | 2025-10-19 | neutrinos are hard to detect |
| 2019 | 58,333 | 6.017M | 2,833.12 | 2025-10-31 | Adam Smith is the father of economics |
| 2020 | 66,667 | 55.958M | 3,066.50 | 2025-11-12 | once upon a time |
| 2021 | 75,000 | 520.411M | 3,299.88 | 2025-11-24 | risk is hard to define |
| 2022 | 83,333 | 4.840G | 3,533.25 | 2025-12-06 | not in Kansas anymore |
| 2023 | 91,667 | 45.010G | 3,766.62 | 2025-12-18 | neutrinos are hard to detect |
| 2024 | 100,000 | 418.596G | 4,000.00 | 2025-12-31 | Adam Smith is the father of economics |
In [66]:
#| echo: fenced
#| label: tbl-hard-rules-3a
#| tbl-cap: No V rules but hrules (Quarto generated caption)
display(sGT(hard.sample(5).sort_index(),
caption='GT caption No v rules, but h rules',
vrule_widths=(0,0,0),
hrule_widths=(1,0,0)))| A | B | C | |||
|---|---|---|---|---|---|
| years! | Int | Float | Float | 3 | Longer Text |
| 2000 | -100,000 | 0 | -1,601.00 | 2025-03-14 | once upon a time |
| 2002 | -83,333 | 0 | -1,134.25 | 2025-04-07 | not in Kansas anymore |
| 2003 | -75,000 | 0 | -900.88 | 2025-04-19 | neutrinos are hard to detect |
| 2008 | -33,333 | 0 | 266.00 | 2025-06-19 | neutrinos are hard to detect |
| 2018 | 50,000 | 646,990 | 2,599.75 | 2025-10-19 | neutrinos are hard to detect |
In [67]:
#| echo: fenced
#| label: tbl-hard-rules-3b
#| tbl-cap: Change date and integer formats (Quarto generated caption)
display(sGT(hard.sample(5).sort_index(),
caption='Change default date and integer formats',
default_date_str='%m-%d', default_integer_str='[{x:d}]'))| A | B | C | |||
|---|---|---|---|---|---|
| years! | Int | Float | Float | 3 | Longer Text |
| 2001 | [-91667] | 0 | -1,367.62 | 03-26 | risk is hard to define |
| 2004 | [-66667] | 0 | -667.50 | 05-01 | Adam Smith is the father of economics |
| 2007 | [-41667] | 0 | 32.62 | 06-07 | not in Kansas anymore |
| 2008 | [-33333] | 0 | 266.00 | 06-19 | neutrinos are hard to detect |
| 2018 | [50000] | 646,990 | 2,599.75 | 10-19 | neutrinos are hard to detect |
In [45]:
#| echo: fenced
#| label: tbl-hard-rules-3c
#| tbl-cap: "Change padding and debug mode, boxes (Quarto generated caption)"
display(sGT(hard.sample(5).sort_index(),
caption='Change padding, debug mode lines',
padding_trbl=(10, 10, 20, 20), debug=True))[6, 7.0, 9.0, 8.0, 10.0, 39.0]
| A | B | C | |||
|---|---|---|---|---|---|
| years! | Int | Float | Float | 3 | Longer Text |
| 2007 | -41,667 | 14.374u | 32.62 | 2025-06-07 | not in Kansas anymore |
| 2008 | -33,333 | 133.681u | 266.00 | 2025-06-19 | neutrinos are hard to detect |
| 2014 | 16,667 | 86.490 | 1,666.25 | 2025-08-31 | Adam Smith is the father of economics |
| 2016 | 33,333 | 7.481k | 2,133.00 | 2025-09-24 | risk is hard to define |
| 2021 | 75,000 | 520.411M | 3,299.88 | 2025-11-24 | risk is hard to define |
In [68]:
#| label: raw-output
f = sGT(hard.head(4), debug=True)
print('HTML output\n')
print(f._repr_html_())
print('\n\n\nTeX output\n')
print(f._repr_latex_())HTML output
<div class="greater-table">
<style>
#TWRLFJOULVHRG {
border-collapse: collapse;
font-family: "Roboto", "Open Sans Condensed", "Arial", 'Segoe UI', sans-serif;
font-size: 0.9em;
width: auto;
/* tb and lr
width: fit-content; */
margin: 10px auto;
border: none;
overflow: auto;
margin-left: auto;
margin-right: auto;
}
/* tag formats */
#TWRLFJOULVHRG caption {
padding: 8px 10px 4px 10px;
font-size: 0.99em;
text-align: center;
font-weight: normal;
caption-side: top;
}
#TWRLFJOULVHRG thead {
/* top and bottom of header */
border-top: 1px solid #0ff;
border-bottom: 1px solid #0ff;
font-size: 0.99em;
}
#TWRLFJOULVHRG tbody {
/* bottom of body */
border-bottom: 1px solid #f0f;
}
#TWRLFJOULVHRG th {
vertical-align: bottom;
padding: 8px 10px 8px 10px;
}
#TWRLFJOULVHRG td {
/* top, right, bottom left cell padding */
padding: 4px 10px 4px 10px;
vertical-align: top;
}
/* class overrides */
#TWRLFJOULVHRG .grt-hrule-0 {
border-top: 0px solid #f00;
}
#TWRLFJOULVHRG .grt-hrule-1 {
border-top: 0px solid #b00;
}
#TWRLFJOULVHRG .grt-hrule-2 {
border-top: 0px solid #900;
}
/* for the header, there if you have v lines you want h lines
hence use vrule_widths */
#TWRLFJOULVHRG .grt-bhrule-0 {
border-bottom: 1.5px solid #f00;
}
#TWRLFJOULVHRG .grt-bhrule-1 {
border-bottom: 1px solid #b00;
}
#TWRLFJOULVHRG .grt-vrule-index {
border-left: 1.5px solid #0f0;
}
#TWRLFJOULVHRG .grt-vrule-0 {
border-left: 1.5px solid #0f0;
}
#TWRLFJOULVHRG .grt-vrule-1 {
border-left: 1px solid #0a0;
}
#TWRLFJOULVHRG .grt-vrule-2 {
border-left: 0.5px solid #090;
}
#TWRLFJOULVHRG .grt-left {
text-align: left;
}
#TWRLFJOULVHRG .grt-center {
text-align: center;
}
#TWRLFJOULVHRG .grt-right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#TWRLFJOULVHRG .grt-head {
font-family: "Times New Roman", 'Courier New';
font-size: 0.99em;
}
#TWRLFJOULVHRG .grt-bold {
font-weight: bold;
}
#TWRLFJOULVHRG .grt-c-0 { width: 5.5em; }
#TWRLFJOULVHRG .grt-c-1 { width: 6.5em; }
#TWRLFJOULVHRG .grt-c-2 { width: 7.0em; }
#TWRLFJOULVHRG .grt-c-3 { width: 7.0em; }
#TWRLFJOULVHRG .grt-c-4 { width: 7.5em; }
#TWRLFJOULVHRG .grt-c-5 { width: 17.0em; }
</style>
<table id="TWRLFJOULVHRG">
<caption> (id: TWRLFJOULVHRG)</caption>
<colgroup>
<col style="width: 2.75em;"/>
<col style="width: 3.25em;"/>
<col style="width: 3.5em;"/>
<col style="width: 3.5em;"/>
<col style="width: 3.75em;"/>
<col style="width: 8.5em;"/>
</colgroup>
<thead>
<tr>
<th class="grt-left"></th>
<th class="grt-center grt-bhrule-0 grt-vrule-index" colspan="2">A</th>
<th class="grt-center grt-bhrule-0 grt-vrule-0" colspan="2">B</th>
<th class="grt-center grt-bhrule-0 grt-vrule-0" colspan="1">C</th>
</tr>
<tr>
<th class="grt-left">years!</th>
<th class="grt-center grt-vrule-index" colspan="1">Int</th>
<th class="grt-center grt-vrule-1" colspan="1">Float</th>
<th class="grt-center grt-vrule-0" colspan="1">Float</th>
<th class="grt-center grt-vrule-1" colspan="1">3</th>
<th class="grt-center grt-vrule-0" colspan="1">Longer Text</th>
</tr>
</thead>
<tbody>
<tr>
<td class="grt-c-0 grt-left">2000</td>
<td class="grt-c-1 grt-right grt-vrule-index">-100,000</td>
<td class="grt-c-2 grt-right grt-vrule-1"> 2.389p</td>
<td class="grt-c-3 grt-right grt-vrule-0">-1,601.00</td>
<td class="grt-c-4 grt-center grt-vrule-1">2025-03-14</td>
<td class="grt-c-5 grt-left grt-vrule-0">once upon a time</td>
</tr>
<tr>
<td class="grt-c-0 grt-left grt-hrule-0">2001</td>
<td class="grt-c-1 grt-right grt-hrule-0 grt-vrule-index">-91,667</td>
<td class="grt-c-2 grt-right grt-hrule-0 grt-vrule-1"> 22.217p</td>
<td class="grt-c-3 grt-right grt-hrule-0 grt-vrule-0">-1,367.62</td>
<td class="grt-c-4 grt-center grt-hrule-0 grt-vrule-1">2025-03-26</td>
<td class="grt-c-5 grt-left grt-hrule-0 grt-vrule-0"> risk is hard to define</td>
</tr>
<tr>
<td class="grt-c-0 grt-left grt-hrule-0">2002</td>
<td class="grt-c-1 grt-right grt-hrule-0 grt-vrule-index">-83,333</td>
<td class="grt-c-2 grt-right grt-hrule-0 grt-vrule-1"> 206.619p</td>
<td class="grt-c-3 grt-right grt-hrule-0 grt-vrule-0">-1,134.25</td>
<td class="grt-c-4 grt-center grt-hrule-0 grt-vrule-1">2025-04-07</td>
<td class="grt-c-5 grt-left grt-hrule-0 grt-vrule-0"> not in Kansas anymore</td>
</tr>
<tr>
<td class="grt-c-0 grt-left grt-hrule-0">2003</td>
<td class="grt-c-1 grt-right grt-hrule-0 grt-vrule-index">-75,000</td>
<td class="grt-c-2 grt-right grt-hrule-0 grt-vrule-1"> 1.922n</td>
<td class="grt-c-3 grt-right grt-hrule-0 grt-vrule-0">-900.88</td>
<td class="grt-c-4 grt-center grt-hrule-0 grt-vrule-1">2025-04-19</td>
<td class="grt-c-5 grt-left grt-hrule-0 grt-vrule-0"> neutrinos are hard to detect</td>
</tr>
</tbody>
</table></div>
TeX output
\begin{tikzpicture}[
auto,
transform shape,
nosep/.style={inner sep=0},
table/.style={
matrix of nodes,
row sep=0.125em,
column sep=0.375em,
nodes in empty cells,
nodes={rectangle, scale=0.635, text badly ragged , draw=blue!10},
row 1/.style={nodes={text=black, anchor=north, inner ysep=0, text height=0, text depth=0}},
row 2/.style={nodes={text=black, anchor=south, inner ysep=.2em, minimum height=1.3em, font=\bfseries}},
row 3/.style={nodes={text=black, anchor=south, inner ysep=.2em, minimum height=1.3em, font=\bfseries}},
column 1/.style={nodes={align=left }, text height=0.9em, text depth=0.2em, inner xsep=0.375em, inner ysep=0, text width=3.60em},
column 2/.style={nodes={align=right }, nosep, text width=6.59em},
column 3/.style={nodes={align=right }, nosep, text width=7.41em},
column 4/.style={nodes={align=right }, nosep, text width=7.41em},
column 5/.style={nodes={align=center}, nosep, text width=8.24em},
column 6/.style={nodes={align=left }, nosep, text width=23.89em},
column 7/.style={text height=0.9em, text depth=0.2em, nosep, text width=0em} }]
\matrix (TWRLFJOULVHRG) [table, ampersand replacement=\&]{
\& \& \& \& \& \& \\
\grtspacer \& A\grtspacer \& \grtspacer \& B\grtspacer \& \grtspacer \& C\grtspacer \& \\
years!\grtspacer \& Int\grtspacer \& Float\grtspacer \& Float\grtspacer \& 3\grtspacer \& Longer Text\grtspacer \& \\
2000 \& -100,000 \& 2.389p \& -1,601.00 \& 2025-03-14 \& once upon a time \& \\
2001 \& -91,667 \& 22.217p \& -1,367.62 \& 2025-03-26 \& risk is hard to define \& \\
2002 \& -83,333 \& 206.619p \& -1,134.25 \& 2025-04-07 \& not in Kansas anymore \& \\
2003 \& -75,000 \& 1.922n \& -900.88 \& 2025-04-19 \& neutrinos are hard to detect \& \\
};
\path[draw, thick] (TWRLFJOULVHRG-1-1.south west) -- (TWRLFJOULVHRG-1-7.south east);
\path[draw, semithick] ([yshift=-0.0625em]TWRLFJOULVHRG-3-1.south west) -- ([yshift=-0.0625em]TWRLFJOULVHRG-3-7.south east);
\path[draw, thick] ([yshift=-0.3125em]TWRLFJOULVHRG-7-1.base west) -- ([yshift=-0.3125em]TWRLFJOULVHRG-7-7.base east);
\path[draw, very thin] ([xshift=-0.1875em, yshift=-0.0625em]TWRLFJOULVHRG-2-2.south west) -- ([yshift=-0.0625em]TWRLFJOULVHRG-2-7.south east);
\path[draw, very thin] ([xshift=-0.1875em]TWRLFJOULVHRG-1-2.south west) -- ([yshift=-0.3125em, xshift=-0.1875em]TWRLFJOULVHRG-7-2.base west);
\path[draw, ultra thin] ([xshift=0.1875em, yshift=-0.0625em]TWRLFJOULVHRG-1-3.south east) -- ([yshift=-0.3125em, xshift=0.1875em]TWRLFJOULVHRG-7-3.base east);
\path[draw, ultra thin] ([xshift=0.1875em, yshift=-0.0625em]TWRLFJOULVHRG-1-5.south east) -- ([yshift=-0.3125em, xshift=0.1875em]TWRLFJOULVHRG-7-5.base east);
\end{tikzpicture}
In [69]:
#| label: tbl-tex
#| tbl-cap: '(Quarto generated caption): table displayed by default routine.'
index = pd.Index(["A", "B", "$C_1$", "C_2 not tex", '$\\cos(A)$'])
tex = pd.DataFrame(
{'x': np.arange(2020, 2025, dtype=int),
'b': np.random.random(5),
'a1': [f'$x^{i}$' for i in range(5,10)],
'a2': [f'$\\sin({i}x\\pi/n)$' for i in range(5,10)],
'a3': [f'$x^{i}$' for i in range(5,10)],
'a4': [f'\\(x^{i}\\)' for i in range(5,10)],
}).set_index('x')
tex = tex.head()
tex.columns = index
texOut [69]:
| A | B | $C_1$ | C_2 not tex | $\cos(A)$ | |
|---|---|---|---|---|---|
| x | |||||
| 2020 | 0.424657 | $x^5$ | $\sin(5x\pi/n)$ | $x^5$ | \(x^5\) |
| 2021 | 0.209278 | $x^6$ | $\sin(6x\pi/n)$ | $x^6$ | \(x^6\) |
| 2022 | 0.068308 | $x^7$ | $\sin(7x\pi/n)$ | $x^7$ | \(x^7\) |
| 2023 | 0.797205 | $x^8$ | $\sin(8x\pi/n)$ | $x^8$ | \(x^8\) |
| 2024 | 0.519346 | $x^9$ | $\sin(9x\pi/n)$ | $x^9$ | \(x^9\) |
In [70]:
#| label: tbl-tex-2
#| tbl-cap: GT output (Quarto generated caption)
sGT(tex, 'GT Caption')Out [70]:
| x | A | B | \(C_1\) | C_2 not tex | \(\cos(A)\) |
|---|---|---|---|---|---|
| 2020 | 0.42466 | \(x^5\) | \(\sin(5x\pi/n)\) | \(x^5\) | \(x^5\) |
| 2021 | 0.20928 | \(x^6\) | \(\sin(6x\pi/n)\) | \(x^6\) | \(x^6\) |
| 2022 | 0.06831 | \(x^7\) | \(\sin(7x\pi/n)\) | \(x^7\) | \(x^7\) |
| 2023 | 0.79721 | \(x^8\) | \(\sin(8x\pi/n)\) | \(x^8\) | \(x^8\) |
| 2024 | 0.51935 | \(x^9\) | \(\sin(9x\pi/n)\) | \(x^9\) | \(x^9\) |
In [71]:
#| label: tbl-tex-3
#| tbl-cap: greater table output
tex.columns = ["A (%)", "B", "$C_1$", "C_2 not tex", '$\\cos(A)$']
sGT(tex, 'Ratio columns in A', ratio_cols='A (%)')Out [71]:
| x | A (%) | B | \(C_1\) | C_2 not tex | \(\cos(A)\) |
|---|---|---|---|---|---|
| 2020 | 42.5% | \(x^5\) | \(\sin(5x\pi/n)\) | \(x^5\) | \(x^5\) |
| 2021 | 20.9% | \(x^6\) | \(\sin(6x\pi/n)\) | \(x^6\) | \(x^6\) |
| 2022 | 6.8% | \(x^7\) | \(\sin(7x\pi/n)\) | \(x^7\) | \(x^7\) |
| 2023 | 79.7% | \(x^8\) | \(\sin(8x\pi/n)\) | \(x^8\) | \(x^8\) |
| 2024 | 51.9% | \(x^9\) | \(\sin(9x\pi/n)\) | \(x^9\) | \(x^9\) |
In [72]:
#| echo: true
#| label: greater-tables-test
test_gen = gtu.TestDFGenerator(0, 0)
ans = test_gen.test_suite() In [73]:
#| echo: true
#| label: tbl-greater-tables-test-0
#| tbl-cap: GT output for test table basic
hrw = (0, 0, 0)
sGT(ans['basic'], "Basic", ratio_cols='z', aligners={'w': 'l'},
hrule_widths=hrw)Out [73]:
| unintentionally | amply float | deeper str | grains date | indicators datetime | inject int | originates str | philosophers int | snowy float |
|---|---|---|---|---|---|---|---|---|
| 8,003 | 12.899M | malicious | 2025-09-08 | 2010-07-06 | -3,452 | contracts | 693,336,903 | 5.120 |
| 18,582 | 858.904 | manufacturers | 2023-05-02 | 2015-06-12 | 7,457 | collapse | 789,639,196 | 765.357m |
| 18,825 | 229.354k | shortfall | 2030-08-24 | 2008-08-21 | -2,476 | sprawl | 741,809,916 | 8.096k |
| 20,431 | 5.300 | plugs | 2023-03-07 | 2019-03-27 | 2,255 | generalize | 993,293,639 | 106.115m |
| 61,650 | 461.180m | setter | 2023-03-07 | 2015-06-12 | 9,625 | downright | 577,547,084 | 178.442k |
| 65,395 | 230.601 | longhorn | 2033-05-29 | 2024-10-10 | -5,797 | humor | 821,555,659 | 2.267M |
| 69,741 | 829.476 | secretly | 2025-02-10 | 2024-09-18 | 9,649 | hills | 99,644,183 | 97.579k |
| 74,709 | 110.246 | strove | 2033-05-29 | 2008-08-21 | 1,255 | monster | 128,426,346 | 404.926k |
| 77,783 | 7.586 | conclusive | 2030-08-24 | 2023-04-29 | 4,827 | proffer | 818,501,173 | 18.774k |
| 97,969 | 10.485k | josephine | 2025-02-10 | 2024-09-18 | 7,937 | permissions | 38,019,258 | 538.646 |
In [74]:
#| echo: true
#| label: tbl-greater-tables-test-1
#| tbl-cap: GT output for test table timeseries
hrw = (0, 0, 0)
sGT(ans['timeseries'], "Timeseries", ratio_cols='z', aligners={'w': 'l'},
hrule_widths=hrw)Out [74]:
| bushes | Acquired Bars Renter date | Bristle Engagement Backwater datetime | Heighten Boning Unlucky float |
|---|---|---|---|
| 2008-07-10 | 2012-05-16 | 2010-10-14 | 517.008E |
| 2009-03-25 | 2026-04-05 | 2020-03-31 | 0.000y |
| 2009-08-09 | 2017-04-25 | 2016-04-01 | -29.269u |
| 2010-02-01 | 2026-04-05 | 2013-07-14 | 0.000y |
| 2010-12-31 | 2024-01-03 | 2016-11-20 | -30.741u |
| 2014-06-20 | 2032-11-16 | 2016-04-01 | 1.250m |
| 2015-02-13 | 2026-04-05 | 2016-11-20 | 335.357f |
| 2018-03-19 | 2012-05-16 | 2029-02-11 | -102.890Z |
| 2018-12-07 | 2024-07-26 | 2019-01-14 | -0.022y |
| 2019-10-29 | 2007-07-13 | 2013-07-14 | 1.216k |
| 2021-08-21 | 2024-10-12 | 2025-07-11 | 43.521a |
| 2021-11-12 | 2007-07-13 | 2031-10-24 | -0.000y |
| 2025-01-01 | 2009-04-13 | 2016-04-01 | -631123020.816Y |
| 2026-01-10 | 2017-04-25 | 2029-02-11 | 0.000y |
| 2026-12-27 | 2017-04-25 | 2016-11-20 | -0.000y |
| 2027-09-20 | 2026-04-05 | 2016-04-01 | 3321909909.577Y |
| 2028-12-23 | 2014-04-09 | 2032-03-29 | -25.876Z |
| 2029-11-14 | 2018-03-16 | 2029-02-11 | -69.776E |
| 2031-04-20 | 2007-07-13 | 2016-04-01 | -2.204k |
| 2031-08-19 | 2032-11-16 | 2019-01-14 | 32915.427Y |
In [75]:
#| echo: true
#| label: tbl-greater-tables-test-2
#| tbl-cap: GT output for test table multiindex
hrw = (1.5, 1.0, 0.5)
sGT(ans['multiindex'], "Multiindex", ratio_cols='z', aligners={'w': 'l'},
hrule_widths=hrw)Out [75]:
| phantom | animal | direction | Bitty Youthful Express float | Immunity Counts Hose date | Pennies Reveals Afresh date | Spotty Paralleling Discreet date | Stanley Quarrel Alligator str |
|---|---|---|---|---|---|---|---|
| 18,496 | assent | 43,086 | 0.00003 | 2010-04-13 | 2033-01-25 | 2033-01-12 | areas |
| 85,780 | 0.36067 | 2027-07-10 | 2032-01-23 | 2025-10-22 | mantra | ||
| crusader | 63,535 | 0.00000 | 2027-07-10 | 2029-09-04 | 2008-11-09 | refers | |
| 87,826 | 0.00003 | 2029-08-31 | 2021-11-14 | 2010-09-03 | ministerial | ||
| magnetic | 10,111 | 0.00462 | 2022-12-07 | 2021-06-14 | 2023-01-22 | woods | |
| 14,350 | 0.00000 | 2010-04-13 | 2022-03-16 | 2023-01-22 | codification | ||
| 43,753 | 0.01100 | 2019-02-17 | 2029-09-04 | 2009-05-18 | object | ||
| 98,682 | 0.00000 | 2027-07-10 | 2033-01-25 | 2009-02-12 | dusty | ||
| 51,439 | assent | 93,001 | 0.00000 | 2031-07-03 | 2021-11-14 | 2020-10-04 | lama |
| crusader | 49,688 | 0.00000 | 2022-12-07 | 2021-11-14 | 2033-01-12 | citizen |
In [76]:
#| echo: true
#| label: tbl-greater-tables-test-3
#| tbl-cap: GT output for test table multicolumns
hrw = (0, 0, 0)
sGT(ans['multicolumns'], "Multicolumns", ratio_cols='z', aligners={'w': 'l'},
hrule_widths=hrw)Out [76]:
| psychic | skirted | ||||
|---|---|---|---|---|---|
| press | ventured | ventured | |||
| stimulation | galling | unopened | pessimism | skin | geneva |
| 5,309 | 0.00001 | penalizing | 2020 | 2030-02-11 | 0.20600 |
| 6,029 | 0.00000 | guise | 2009 | 2022-03-18 | 0.00003 |
| 8,065 | 3.27603 | pseudo | 2008 | 2008-07-27 | 5.65328 |
| 14,749 | 0.04182 | instituted | 2025 | 2009-06-05 | 0.00034 |
| 43,062 | 0.00000 | redeemable | 1995 | 2029-05-29 | 0.00000 |
| 61,872 | 0.19522 | seth | 2006 | 2022-03-18 | 0.00000 |
| 69,979 | 0.22767 | aimless | 2000 | 2028-03-06 | 0.00000 |
| 70,526 | 0.00226 | affirms | 1993 | 2008-07-27 | 0.00035 |
| 81,072 | 0.00000 | spain | 2022 | 2028-03-06 | 0.00000 |
| 89,060 | 0.00001 | underemployed | 2011 | 2008-07-27 | 0.02550 |
In [77]:
#| echo: true
#| label: tbl-greater-tables-test-4
#| tbl-cap: GT output for test table complex
hrw = (1.5, 1.0, 0.5)
sGT(ans['complex'], "Complex", ratio_cols='z', aligners={'w': 'l'},
hrule_widths=hrw)Out [77]:
| casualty | copenhagen | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| negating | simmering | autistic | negating | simmering | ||||||||
| harding | broken | loosened | bachelor | drawings | arbitrated | cashing | angels | beneficiary | lending | studiously | paraplegic | unwieldy |
| 49,146 | brew | 293 | 0.06295 | 2010-05-15 | 2031-06-12 | 1997 | chore | 937,952,742 | 0.00001 | 2031-08-06 | 0.00000 | 2014 |
| 3,426 | 1.96586 | 2013-08-05 | 2029-08-20 | 2008 | race | 804,609,967 | 0.00000 | 2013-10-19 | 0.00138 | 2015 | ||
| 19,871 | 0.00000 | 2028-03-18 | 2011-02-16 | 1993 | economy | 268,719,618 | 0.00001 | 2013-10-19 | 0.00028 | 1994 | ||
| 77,970 | 0.00003 | 2028-03-18 | 2008-09-29 | 2023 | exes | 4,595,844 | 4.23108 | 2013-10-19 | 0.00854 | 2015 | ||
| fastest | 13,856 | 0.00000 | 2008-07-29 | 2007-03-02 | 1995 | intrinsically | 655,235,802 | 0.00009 | 2033-05-09 | 0.00002 | 2004 | |
| 31,418 | 0.00001 | 2031-03-12 | 2028-10-19 | 2019 | cradles | 657,320,759 | 0.00000 | 2018-11-17 | 0.00000 | 2001 | ||
| 35,022 | 0.00000 | 2016-08-01 | 2010-04-21 | 2027 | massage | 283,304,167 | 0.00000 | 2020-09-02 | 0.00549 | 2029 | ||
| 80,108 | 0.17548 | 2031-03-12 | 2017-05-22 | 2018 | puzzled | 925,082,070 | 0.00000 | 2013-10-19 | 1.88962 | 2021 | ||
| fliers | 25,936 | 0.00015 | 2016-09-04 | 2017-12-13 | 2029 | computations | 426,967,583 | 0.00000 | 2032-04-15 | 0.00000 | 1999 | |
| 64,433 | 0.00000 | 2016-06-18 | 2007-05-29 | 2004 | passages | 612,446,471 | 0.00017 | 2032-04-15 | 0.49959 | 2009 | ||
| 80,229 | 0.22559 | 2016-06-18 | 2017-07-05 | 2018 | repeat | 112,776,801 | 6.77617 | 2024-07-09 | 0.00000 | 2022 | ||
| 86,639 | brew | 13,964 | 0.00000 | 2016-08-01 | 2007-03-02 | 2017 | frills | 821,529,783 | 0.07168 | 2014-09-27 | 0.00000 | 2025 |
| 41,593 | 0.00003 | 2008-07-29 | 2007-05-29 | 2016 | endorsing | 806,241,846 | 0.02960 | 2027-10-15 | 0.00001 | 2002 | ||
| 43,850 | 0.00000 | 2007-01-12 | 2011-02-21 | 1991 | editorially | 521,714,110 | 0.22257 | 2031-08-06 | 0.00015 | 2024 | ||
| 82,547 | 0.00000 | 2016-08-01 | 2007-03-02 | 2027 | february | 971,932,927 | 1.45559 | 2015-10-18 | 0.00006 | 1997 | ||
| fastest | 49,901 | 0.00000 | 2027-11-12 | 2029-08-20 | 2022 | fancier | 69,371,825 | 1.23570 | 2008-10-25 | 0.00117 | 2009 | |
| 59,151 | 0.00723 | 2018-04-24 | 2029-11-19 | 2022 | hope | 675,380,408 | 0.08046 | 2015-10-18 | 0.00001 | 1992 | ||
| 85,930 | 0.00000 | 2015-06-24 | 2025-05-14 | 2020 | decried | 923,139,367 | 0.00000 | 2015-10-18 | 0.00001 | 2009 | ||
| fliers | 45,876 | 0.00830 | 2018-12-17 | 2025-05-14 | 2019 | proximate | 721,860,881 | 0.00006 | 2012-02-23 | 0.02256 | 2028 | |
| 74,667 | 0.00000 | 2023-08-03 | 2028-10-13 | 2001 | cautionary | 44,092,454 | 0.00001 | 2008-10-25 | 2.24084 | 2027 | ||
In [78]:
#| echo: true
#| label: tbl-greater-tables-test-5
#| tbl-cap: GT from markdown table input
txt = '''
| **Insured group or insurance product** | **Sat** | **RP** | **RF** |
|:------------------------------------------------------------|:-------:|:------:|:------:|
| Non-standard auto | x | | |
| General liability for judgment proof corporation | x | | |
| Term life insurance | | x | |
| Catastrophe Reinsurance, outside rating agency bounds | | x | |
| High limit property per risk reinsurance | | x | |
| Personal lines for affluent individuals | x | x | |
| Small commercial lines | x | x | |
| Catastrophe reinsurance, within rating agency bounds | x | x | |
| Large account captive reinsurance | | | x |
| Structured quota share, requiring a risk transfer test | x | | x |
| Working layer casualty excess of loss | | x | x |
| Surplus relief quota share on cat exposed line | x | x | x |
| Middle market commercial lines work comp or commercial auto | x | x | x |
'''
GT(txt)Out [78]:
| Insured group or insurance product | Sat | RP | RF |
|---|---|---|---|
| Non-standard auto | x | ||
| General liability for judgment proof corporation | x | ||
| Term life insurance | x | ||
| Catastrophe Reinsurance, outside rating agency bounds | x | ||
| High limit property per risk reinsurance | x | ||
| Personal lines for affluent individuals | x | x | |
| Small commercial lines | x | x | |
| Catastrophe reinsurance, within rating agency bounds | x | x | |
| Large account captive reinsurance | x | ||
| Structured quota share, requiring a risk transfer test | x | x | |
| Working layer casualty excess of loss | x | x | |
| Surplus relief quota share on cat exposed line | x | x | x |
| Middle market commercial lines work comp or commercial auto | x | x | x |
In [83]:
x = None
if x:
print(123)In [79]:
#| echo: true
#| label: tbl-greater-tables-test-6
#| tbl-cap: GT output for list of lists input
lol = [['a', 'b', 'c', 'd'], ['west', 10, 20, 30], ['east', 10, 200, 30], ['north', 10, 20, 300], ['south', 100, 20, 30]]
GT(lol)Out [79]:
| a | b | c | d |
|---|---|---|---|
| west | 10 | 20 | 30 |
| east | 10 | 200 | 30 |
| north | 10 | 20 | 300 |
| south | 100 | 20 | 30 |
In [80]:
f = GT(lol)
fOut [80]:
| a | b | c | d |
|---|---|---|---|
| west | 10 | 20 | 30 |
| east | 10 | 200 | 30 |
| north | 10 | 20 | 300 |
| south | 100 | 20 | 30 |
In [87]:
tbl = '''
Var | Amount
:---|------:
A | 100.0
B | 0.123
C | A string
'''
def ff(x):
if abs(x) < 1:
return f'{x:.1%}'
else:
return f'{x:,.2f}'
sGT(tbl, table_float_format=ff)Out [87]:
| Var | Amount |
|---|---|
| A | 100.00 |
| B | 12.3% |
| C | A string |
In [88]:
P = 1000 * 1.075**-10 + 120
L = 1000
ry = .1
v = 1/(1+ry)
T = 10
pv = P - v**T * L
fv = pv / v**T
pv, fvOut [88]:
(219.6506388719328, 569.7171884302238)
In [ ]: