using tfoot
in dataframes for more information¤
while exploring techniques that make dataframes better for screen readers.
i found resources on the tfoot
element. i rarely see it used it with dataframes.
this work explores what a footer description might look like.
%reload_ext pidgy
INTERACTIVE = "__file__" not in locals()
<details markdown="1">
<summary>import functions that make dataframes more useful on screen readers</summary>
{% filter md %}
with __import__('midgy.loader').loader.Markdown(extensions=[".ipynb"]):
from tonyfast.xxiii.__accessible_dataframes_basic_indexes import (
df, soup, set_caption,
set_col_scope, set_row_scope, set_squashed_th,
set_header_titles, strip_class_ids
)
{% endfilter %}
</details>
import functions that make dataframes more useful on screen readers
with __import__('midgy.loader').loader.Markdown(extensions=[".ipynb"]):
from tonyfast.xxiii.__accessible_dataframes_basic_indexes import (
df, soup, set_caption,
set_col_scope, set_row_scope, set_squashed_th,
set_header_titles, strip_class_ids
)
## set `tfoot`
`<tfoot>` is meant to contain supplementary `<table>` information.
def set_tfoot(df, caption=None):
`set_tfoot` sets the footer as `df.describe`
tfoot = soup(strip_class_ids(df.describe().style.to_html())).select_one("tbody")
tfoot.name = "tfoot"
with_footer = soup(df.style.set_caption(caption).to_html())
with_footer.select_one("table").append(tfoot)
return str(with_footer)
set tfoot
¤
<tfoot>
is meant to contain supplementary <table>
information.
def set_tfoot(df, caption=None):
set_tfoot
sets the footer as df.describe
tfoot = soup(strip_class_ids(df.describe().style.to_html())).select_one("tbody")
tfoot.name = "tfoot"
with_footer = soup(df.style.set_caption(caption).to_html())
with_footer.select_one("table").append(tfoot)
return str(with_footer)
formatting the final dataframe¤
def format_df(df, caption=None):
return strip_class_ids(set_header_titles(set_squashed_th(
set_row_scope(set_col_scope(set_tfoot(df, caption=caption))))))
final_table = format_df(df, "a value-less dataframe with thead, tbody and tfoot defined. tfoot are statistical descriptions of the data.")
def format_df(df, caption=None):
return strip_class_ids(set_header_titles(set_squashed_th(
set_row_scope(set_col_scope(set_tfoot(df, caption=caption))))))
final_table = format_df(df, "a value-less dataframe with thead, tbody and tfoot defined. tfoot are statistical descriptions of the data.")
<details>
<summary>import tests from another work.</summary>
{% filter md %}
with __import__('midgy.loader').loader.Markdown(extensions=[".ipynb"]):
from tonyfast.xxiii.__accessible_dataframes_basic_indexes import (
assert_has_col_scope, assert_has_row_scope, assert_no_blank_header, assert_has_caption
)
{% endfilter %}
</details>
import tests from another work.
with __import__('midgy.loader').loader.Markdown(extensions=[".ipynb"]):
from tonyfast.xxiii.__accessible_dataframes_basic_indexes import (
assert_has_col_scope, assert_has_row_scope, assert_no_blank_header, assert_has_caption
)
verifying that we pass our tests¤
def test_basic_table_accessibility(html):
test for a caption, scope attributes, and populated headers
assert_has_caption(html)
assert_has_col_scope(html)
assert_has_row_scope(html)
assert_no_blank_header(html)
def test_basic_table_accessibility(html):
test for a caption, scope attributes, and populated headers
assert_has_caption(html)
assert_has_col_scope(html)
assert_has_row_scope(html)
assert_no_blank_header(html)
the final_table
¤
INTERACTIVE and print("this message means our table abides. woo!")
INTERACTIVE and print("this message means our table abides. woo!")
{{final_table}}
remediated `pandas.DataFrame`
```html
{{final_table}}
```
index | A | B | C |
---|---|---|---|
0 | nan | nan | nan |
1 | nan | nan | nan |
count | 0 | 0 | 0 |
unique | 0 | 0 | 0 |
top | nan | nan | nan |
freq | nan | nan | nan |
remediated pandas.DataFrame
<style type="text/css">
</style>
<table id="T_6ae36">
<caption>a value-less dataframe with thead, tbody and tfoot defined. tfoot are statistical descriptions of the data.</caption>
<thead><tr><th scope="col">index</th><th scope="col" title="apple">A</th><th scope="col" title="banana">B</th><th scope="col" title="carrot">C</th></tr></thead>
<tbody>
<tr>
<th scope="row">0</th>
<td>nan</td>
<td>nan</td>
<td>nan</td>
</tr>
<tr>
<th scope="row">1</th>
<td>nan</td>
<td>nan</td>
<td>nan</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">count</th>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th scope="row">unique</th>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th scope="row">top</th>
<td>nan</td>
<td>nan</td>
<td>nan</td>
</tr>
<tr>
<th scope="row">freq</th>
<td>nan</td>
<td>nan</td>
<td>nan</td>
</tr>
</tfoot></table>