基于ProPublica的tableFu,在Python中操作电子表格和表格的工具
python-tablefu的Python项目详细描述
python tablefu是一个在python中处理类似电子表格的表的工具。它最初是ProPublica的[TableFu]的Python实现(http://propublica.github.com/table fu/),不过添加了新方法。tablefu允许数据的过滤、切面和操作。接下来,该项目旨在为电子表格创建类似于ORM的内容。
用法:
----
>;>;from table懔fu import tablefu
>;>;table=tablefu.from懔file('tests/test.csv')
>;>;table.columns
['author','best book','页数','样式']
#筛选表返回一个新实例
>;>t2=表。筛选(style='modernism')
>;>list(t2)
[<;行:samuel beckett,malone muert,120,modernism>;,
<;行:james joyce,ulysses,644,modernism>;]
实例的行为类似于行列表
>;>table[0]
<;行:samuel beckett,malone muert,120,modernism>;
list(table.rows)
[<;行:samuel beckett,malone muert,120,modernism>;,
<;行:james joyce,ulysses,644,modernism>;,
<;row:nicholson baker,mezannine,150,极简主义>;,
<;row:vladimir sorokin,the queue,263,satire>;]
打印行["author"]
james joyce
<;行:样式、现代主义、现代主义、极简主义、讽刺艺术>;]table.sort('author')
>;>;table.rows
[<;row:詹姆斯·乔伊斯,尤利西斯,644,现代主义>;,
<;row:尼克尔森·贝克,梅赞宁,150,极简主义>;,
<;row:塞缪尔·贝克特,马龙·穆尔特,120,现代主义>;,
<;row:弗拉基米尔·索罗金,队列,263,satire>;]
对于表中的t。facet_by('style'):
…打印t.faceted_on
…T.table
极简主义
[['nicholson baker','mezannine','150','minimalism']]
现代主义
['samuel beckett','malone muert','120','modernism'],
['james joyce','ulysses','644','modernism']]
讽刺
['vladimir sorokin','the queue','263,"讽刺"]
key=0aprnp7zjiys1dg5wbvjpwtvacwpuuh5vhuxmk1wtee&hl=en&;authkey=cjfb5myp(从纽约时报国会api中提取)。
包含的格式化程序类。
>>gt;来自表"格式导入格式化程序"
>;>;format=formatter()
>;>;def capital(value,*args):
…返回str(value).capital()
>;>;>;格式。register(大写)
>;>;print format('foo','capital')
foo
>;>table.columns
['name','url','about']
>;>table.formatting={
…'名称':{'filter':'link','args':['url']}
…}
>;>>打印表[0]['name']
<;a href="http://www.chrisamico.com"title="chrisamico.com">;chrisamico.com<;/a>;
--用法:
----
>;>;from table懔fu import tablefu
>;>;table=tablefu.from懔file('tests/test.csv')
>;>;table.columns
['author','best book','页数','样式']
#筛选表返回一个新实例
>;>t2=表。筛选(style='modernism')
>;>list(t2)
[<;行:samuel beckett,malone muert,120,modernism>;,
<;行:james joyce,ulysses,644,modernism>;]
实例的行为类似于行列表
>;>table[0]
<;行:samuel beckett,malone muert,120,modernism>;
list(table.rows)
[<;行:samuel beckett,malone muert,120,modernism>;,
<;行:james joyce,ulysses,644,modernism>;,
<;row:nicholson baker,mezannine,150,极简主义>;,
<;row:vladimir sorokin,the queue,263,satire>;]
打印行["author"]
james joyce
<;行:样式、现代主义、现代主义、极简主义、讽刺艺术>;]table.sort('author')
>;>;table.rows
[<;row:詹姆斯·乔伊斯,尤利西斯,644,现代主义>;,
<;row:尼克尔森·贝克,梅赞宁,150,极简主义>;,
<;row:塞缪尔·贝克特,马龙·穆尔特,120,现代主义>;,
<;row:弗拉基米尔·索罗金,队列,263,satire>;]
对于表中的t。facet_by('style'):
…打印t.faceted_on
…T.table
极简主义
[['nicholson baker','mezannine','150','minimalism']]
现代主义
['samuel beckett','malone muert','120','modernism'],
['james joyce','ulysses','644','modernism']]
讽刺
['vladimir sorokin','the queue','263,"讽刺"]
key=0aprnp7zjiys1dg5wbvjpwtvacwpuuh5vhuxmk1wtee&hl=en&;authkey=cjfb5myp(从纽约时报国会api中提取)。
包含的格式化程序类。
>>gt;来自表"格式导入格式化程序"
>;>;format=formatter()
>;>;def capital(value,*args):
…返回str(value).capital()
>;>;>;格式。register(大写)
>;>;print format('foo','capital')
foo
>;>table.columns
['name','url','about']
>;>table.formatting={
…'名称':{'filter':'link','args':['url']}
…}
>;>>打印表[0]['name']
<;a href="http://www.chrisamico.com"title="chrisamico.com">;chrisamico.com<;/a>;
>;table=tablefu(open('tests/sites.csv'))
>;>table.columns
['name','url','about']
>;>table.formatting={'name':{'filter:'link','args':['url']}
>;>table.columns='name','about'
>;>print table.html()
<;表>;
<;thead>;
<;tr>;<;th>;名称<;/th>;<;th>;关于<;/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">;我的个人网站和博客<;/td>;<;/tr>;
<;tr id="row1"class="row odd">;<;td class="datum">;<;a href="http://www.propublica.org"title="propublica">;propublica<;/a>;<;td class="datum">;建设者这个库的Ruby版本的<;/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">;我在那里度过我的每一天<;/td>;<;/tr>;
<;/tbody>;
<;/表格>;