skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
using tfoot in dataframes for more information
description
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.
cells
12 total
8 code
state
executed in order
kernel
Python [conda env:root] *
language
python
name
conda-root-py
lines of code
54
outputs
8
table of contents
{"kernelspec": {"display_name": "Python [conda env:root] *", "language": "python", "name": "conda-root-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13"}, "title": "using tfoot in dataframes for more information", "description": "while exploring techniques that make dataframes better for screen readers.\ni found resources on the tfoot element. i rarely see it used it with dataframes.\nthis work explores what a footer description might look like."}
notebook toolbar
Activate
cell ordering
1

using 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.

2
3 1 outputs.
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
    )
4 1 outputs.

set

<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)
5

formatting the final dataframe

6 1 outputs.
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.")
7 1 outputs.
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
    )
8

verifying that we pass our tests

9 1 outputs.
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)
10

the

11 2 outputs.
this message means our table abides. woo!

INTERACTIVE and print("this message means our table abides. woo!")
12 1 outputs.
a value-less dataframe with thead, tbody and tfoot defined. tfoot are statistical descriptions of the data.
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>