python-tablefu

A tool for manipulating spreadsheets and tables in Python, based on ProPublica's TableFu
Download

python-tablefu Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Chris Amico

python-tablefu Tags


python-tablefu Description

A tool for manipulating spreadsheets and tables in Python, based on ProPublica's TableFu This is a Python implementation of ProPublica's (http://propublica.github.com/table-fu/). This API is similar, though following Python conventions.Usage: > > > from table_fu import TableFu > > > csv = open('tests/test.csv') > > > table = TableFu(csv) > > > table.columns # get all authors > > > table.values('Author') # total a column > > > table.total('Number of Pages') 1177.0 # each TableFu instance acts like a list of rows > > > table < Row: Samuel Beckett, Malone Muert, 120, Modernism > table.rows # rows, in turn, act like dictionaries > > > row = table > > > print row James Joyce # sort rows > > > table.sort('Author') > > > table.rows # sorting is stored table.options {'Author': {'reverse': False}} # which is handy because... # tables can also be faceted (and options are copied to new tables) > > > for t in table.facet_by('Style'): ... print t.faceted_on ... t.table Minimalism ] Modernism , ] Satire ]Formatting:Filters are just functions that take a value and some number of positional arguments.New filters can be registered with the included Formatter class. > > > from table_fu.formatting import Formatter > > > format = Formatter() > > > def capitalize(value, *args): ... return str(value).capitalize() > > > format.register(capitalize) > > > print format('foo', 'capitalize') FooCells can be formatted according to rules of the table (which carry over if the table is faceted): > > > table = TableFu(open('tests/sites.csv')) > > > table.columns > > > table.formatting = { ... 'Name': {'filter': 'link', 'args': } ... } > > > print table < a href="http://www.chrisamico.com" title="ChrisAmico.com" >ChrisAmico.com< /a >HTML OutputTableFu can output an HTML table, using formatting you specify: > > > table = TableFu(open('tests/sites.csv')) > > > table.columns > > > table.formatting = {'Name': {'filter: 'link', 'args': }} > > > table.columns = 'Name', 'About' > > > print table.html() < table > < thead > < tr >< th >Name< /th >< th >About< /th >< /tr > < /thead > < tbody > < tr id="row0" class="row even" >< td class="datum" >< a href="http://www.chrisamico.com" title="ChrisAmico.com" >ChrisAmico.com< /a >< /td >< td class="datum" >My personal site and blog< /td >< /tr > < tr id="row1" class="row odd" >< td class="datum" >< a href="http://www.propublica.org" title="ProPublica" >ProPublica< /a >< /td >< td class="datum" >Builders of the Ruby version of this library< /td >< /tr > < tr id="row2" class="row even" >< td class="datum" >< a href="http://www.pbs.org/newshour" title="PBS NewsHour" >PBS NewsHour< /a >< /td >< td class="datum" >Where I spend my days< /td >< /tr > < /tbody > < /table > Requirements: · Python


python-tablefu Related Software