本文整理汇总了Python中table_fu.TableFu类的典型用法代码示例。如果您正苦于以下问题:Python TableFu类的具体用法?Python TableFu怎么用?Python TableFu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableFu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_map_values
def test_map_values(self):
"""
Test mapping a function to specific column values
"""
t = TableFu(self.table)
result = [s.lower() for s in t.values('Style')]
self.assertEqual(result, t.map(str.lower, 'Style'))
示例2: test_sort_option_int
def test_sort_option_int(self):
"Sorting the table by an int field, Number of Pages"
t = TableFu(self.csv_file)
pages = t.values('Number of Pages')
pages = sorted(pages, reverse=True)
t.sort('Number of Pages', reverse=True)
self.assertEqual(t.values('Number of Pages'), pages)
示例3: test_row_map
def test_row_map(self):
"""
Test map a function to rows, or a subset of fields
"""
t = TableFu(self.table)
result = [s.lower() for s in t.values('Style')]
self.assertEqual(result, t.map(lambda row: row['Style'].value.lower()))
示例4: test_limit_columns
def test_limit_columns(self):
"Column definitions are passed to rows"
t = TableFu(self.csv_file)
t.columns = ['Author', 'Style']
self.assertEqual(
str(t[0]),
'Samuel Beckett, Modernism'
)
示例5: test_facet
def test_facet(self):
"Facet tables based on shared column values"
t = TableFu(self.csv_file)
tables = t.facet_by('Style')
style_row = self.table[4]
self.assertEqual(
style_row,
tables[2][0].cells
)
示例6: test_cell_format
def test_cell_format(self):
"Format a cell"
t = TableFu(self.csv_file)
t.formatting = {'Name': {'filter': 'link', 'args': ['URL']}}
self.assertEqual(
str(t[0]['Name']),
'<a href="http://www.chrisamico.com" title="ChrisAmico.com">ChrisAmico.com</a>'
)
示例7: testFacets
def testFacets(self):
table = Table(self.yml)
options = self.parsed['table']['column_options']
url = "http://spreadsheets.google.com/pub?key=tcSL0eqrj3yb5d6ljak4Dcw&output=csv"
response = urllib2.urlopen(url)
tf = TableFu(response, **options)
tables = tf.facet_by('State')
for i, t in enumerate(tables):
self.assertEqual(t.table, table.data[i].table)
示例8: test_transform_to_int
def test_transform_to_int(self):
"""
Convert the Number of Pages field to integers
"""
t = TableFu(self.csv_file)
pages = t.values('Number of Pages')
t.transform('Number of Pages', int)
for s, i in zip(pages, t.values('Number of Pages')):
self.assertEqual(int(s), i)
示例9: test_map_many_values
def test_map_many_values(self):
"""
Test mapping a function to multiple columns
"""
t = TableFu(self.table)
result = [
[s.lower() for s in t.values(value)]
for value in ['Best Book', 'Style']
]
self.assertEqual(result, t.map(str.lower, 'Best Book', 'Style'))
示例10: test_sort
def test_sort(self):
"Sort a table in place"
t = TableFu(self.csv_file)
self.table.pop(0)
self.table.sort(key=lambda row: row[0])
t.sort('Author')
self.assertEqual(
t[0].cells,
self.table[0]
)
示例11: _open
def _open(self):
if self.url:
f = urllib2.urlopen(self.url)
elif self.filename:
f = open(self.filename, 'rb')
else: # there's neither a url nor a file
raise TableError("You must specify a google_key, URL or local file containing CSV data")
t = TableFu(f, **self.options.get('column_options', {}))
if self.options.get('faceting', False):
return t.facet_by(self.options['faceting']['facet_by'])
return t
示例12: test_json
def test_json(self):
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
return
t = TableFu(self.csv_file)
self.csv_file.seek(0)
reader = csv.DictReader(self.csv_file)
jsoned = json.dumps([row for row in reader])
self.assertEqual(t.json(), jsoned)
示例13: test_from_url
def test_from_url(self):
if not os.getenv('TEST_REMOTE'):
return True
url = "http://spreadsheets.google.com/pub?key=thJa_BvqQuNdaFfFJMMII0Q&output=csv"
t1 = TableFu.from_url(url)
t2 = TableFu(urllib2.urlopen(url))
self.assertEqual(t1.table, t2.table)
示例14: csvviresult
def csvviresult():
global table
# data = request.form['text']
# table = TableFu.from_file('app/vi-csv.csv')
table = TableFu.from_file('app/vi-csv.csv')
# return render_template('vi-template.html', table=table)
return render_template('vi-template.html', table=table)
示例15: test_transpose
def test_transpose(self):
t = TableFu(self.table)
result = [
['Author', 'Samuel Beckett', 'James Joyce', 'Nicholson Baker', 'Vladimir Sorokin'],
['Best Book', 'Malone Muert', 'Ulysses', 'Mezannine', 'The Queue'],
['Number of Pages', '120', '644', '150', '263'],
['Style', 'Modernism', 'Modernism', 'Minimalism', 'Satire']
]
transposed = t.transpose()
self.assertEqual(transposed.table, result[1:])
self.assertEqual(transposed.columns, [
'Author',
'Samuel Beckett',
'James Joyce',
'Nicholson Baker',
'Vladimir Sorokin'
])