index
execution_count
cell_type
toolbar
started_at
completed_at
source
loc
metadata
outputs
1
unexecuted
In
[
]
markdown
# 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.
metadata
5
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
executed
In
[
1
]
code
% reload_ext pidgy
INTERACTIVE = "__file__" not in locals ()
metadata
3
0 outputs.
Out
[
1
]
3
executed
In
[
2
]
code
< 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 >
metadata
13
1 outputs.
Out
[
2
]
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
executed
In
[
3
]
code
## 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 )
metadata
12
1 outputs.
Out
[
3
]
<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
unexecuted
In
[
]
markdown
## formatting the final dataframe
metadata
1
6
executed
In
[
4
]
code
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." )
metadata
5
1 outputs.
Out
[
4
]
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
executed
In
[
5
]
code
< 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 >
metadata
11
1 outputs.
Out
[
5
]
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
unexecuted
In
[
]
markdown
### verifying that we pass our tests
metadata
1
9
executed
In
[
6
]
code
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 )
metadata
7
1 outputs.
Out
[
6
]
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
unexecuted
In
[
]
markdown
metadata
1
11
executed
In
[
7
]
code
INTERACTIVE and print ( "this message means our table abides. woo!" )
metadata
1
2 outputs.
Out
[
7
]
this message means our table abides. woo!
INTERACTIVE and print("this message means our table abides. woo!")
12
executed
In
[
8
]
code
{{ final_table }}
remediated ` pandas . DataFrame `
``` html
{{ final_table }}
```
metadata
7
1 outputs.
Out
[
8
]
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 >