本文整理汇总了Python中outputty.Table.order_by方法的典型用法代码示例。如果您正苦于以下问题:Python Table.order_by方法的具体用法?Python Table.order_by怎么用?Python Table.order_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.order_by方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ordering_table_without_data
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_table_without_data(self):
my_table = Table(headers=["ham", "spam", "eggs"])
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+-----+------+------+
| ham | spam | eggs |
+-----+------+------+
"""
).strip(),
)
示例2: test_ordering_ascending
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_ascending(self):
table = Table(headers=["spam"])
table.extend([[5], [3], [7], [10]])
table.order_by("spam", "ascending")
table_2 = Table(headers=["spam"])
table_2.extend([[5], [3], [7], [10]])
table_2.order_by("spam", "asc")
table_3 = Table(headers=["spam"])
table_3.extend([[5], [3], [7], [10]])
table_3.order_by("spam", "ASCENDING")
table_4 = Table(headers=["spam"])
table_4.extend([[5], [3], [7], [10]])
table_4.order_by("spam", "ASC")
expected_output = dedent(
"""
+------+
| spam |
+------+
| 3 |
| 5 |
| 7 |
| 10 |
+------+
"""
).strip()
self.assertEqual(str(table), expected_output)
self.assertEqual(str(table_2), expected_output)
示例3: test_order_by_method_should_order_ascending_by_default
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_order_by_method_should_order_ascending_by_default(self):
table = Table(headers=["spam"])
table.extend([[5], [3], [7], [10]])
table.order_by("spam")
expected_output = dedent(
"""
+------+
| spam |
+------+
| 3 |
| 5 |
| 7 |
| 10 |
+------+
"""
).strip()
self.assertEqual(str(table), expected_output)
示例4: test_order_by_method_should_order_data_internally
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_order_by_method_should_order_data_internally(self):
my_table = Table(headers=["spam", "ham", "eggs"])
my_table.append({"spam": "Eric", "eggs": "Idle"})
my_table.append({"ham": "John", "eggs": "Cleese"})
my_table.append({"ham": "Terry", "spam": "Jones"})
my_table.order_by("spam", "asc")
expected_output = dedent(
"""
+-------+-------+--------+
| spam | ham | eggs |
+-------+-------+--------+
| None | John | Cleese |
| Eric | None | Idle |
| Jones | Terry | None |
+-------+-------+--------+
"""
).strip()
self.assertEqual(str(my_table), expected_output)
示例5: test_ordering_unicode
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_unicode(self):
my_table = Table(headers=["spam"])
my_table.append(["á"])
my_table.append(["Á"])
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+------+
| spam |
+------+
| Á |
| á |
+------+
"""
).strip(),
)
示例6: test_ordering_two_columns_table_by_second_header
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_two_columns_table_by_second_header(self):
my_table = Table(headers=["spam", "ham"])
my_table.append(("eggs", "ham"))
my_table.append(("ham", "eggs"))
my_table.append(("ham", "123"))
my_table.order_by("ham")
output = dedent(
"""
+------+------+
| spam | ham |
+------+------+
| ham | 123 |
| ham | eggs |
| eggs | ham |
+------+------+
"""
).strip()
self.assertEqual(str(my_table), output)
示例7: test_ordering_table_with_one_column
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_table_with_one_column(self):
my_table = Table(headers=["spam"])
my_table.append(["ham"])
my_table.append(["eggs"])
my_table.append(["idle"])
my_table.order_by("spam")
output = dedent(
"""
+------+
| spam |
+------+
| eggs |
| ham |
| idle |
+------+
"""
).strip()
self.assertEqual(str(my_table), output)
示例8: test_ordering_numbers_as_strings
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_numbers_as_strings(self):
my_table = Table(headers=["spam"])
my_table.append(["5"])
my_table.append([31])
my_table.append(["42"])
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+------+
| spam |
+------+
| 31 |
| 42 |
| 5 |
+------+
"""
).strip(),
)
示例9: test_ordering_numbers
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_numbers(self):
my_table = Table(headers=["spam"])
my_table.append([5])
my_table.append([42])
my_table.append([3.14])
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+------+
| spam |
+------+
| 3.14 |
| 5 |
| 42 |
+------+
"""
).strip(),
)
示例10: test_ordering_table_with_missing_column_in_some_rows
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_table_with_missing_column_in_some_rows(self):
my_table = Table(headers=["ham", "spam", "eggs"])
my_table.append({"spam": "Eric", "eggs": "Idle"})
my_table.append({"ham": "John", "eggs": "Cleese"})
my_table.append({"ham": "Terry", "spam": "Jones"})
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+-------+-------+--------+
| ham | spam | eggs |
+-------+-------+--------+
| John | None | Cleese |
| None | Eric | Idle |
| Terry | Jones | None |
+-------+-------+--------+
"""
).strip(),
)
示例11: test_ordering_table_with_rows_as_dict_list_tuple
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
def test_ordering_table_with_rows_as_dict_list_tuple(self):
my_table = Table(headers=["ham", "spam", "eggs"])
my_table.append({"ham": "eggs", "spam": "ham", "eggs": "spam"})
my_table.append({"ham": "eggs", "spam": "python", "eggs": "spam"})
my_table.append([1, 42, 3])
my_table.append([3.14, 2.71, 0.0])
my_table.append(("spam", "eggs", "ham"))
my_table.order_by("spam")
self.assertEqual(
str(my_table),
dedent(
"""
+------+--------+------+
| ham | spam | eggs |
+------+--------+------+
| 3.14 | 2.71 | 0.0 |
| 1 | 42 | 3 |
| spam | eggs | ham |
| eggs | ham | spam |
| eggs | python | spam |
+------+--------+------+
"""
).strip(),
)
示例12: Plotter
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
class Plotter(object):
'Stores information about a plot and plot it'
def __init__(self, data=None, rows=1, cols=1, width=1024, height=768):
self.rows = rows
self.cols = cols
self._subplot_number = 0
self.fig = figure(figsize=(width / 80, height / 80), dpi=80)
self._load_data(data)
def _load_data(self, data):
self.data = Table()
self.data.read('csv', data)
def _get_new_subplot(self, projection=None):
self._subplot_number += 1
if self._subplot_number > self.rows * self.cols:
raise OverflowError('This figure can handle only %d subplots' % \
self.rows * self.cols)
if projection is not None:
return self.fig.add_subplot(self.rows, self.cols,
self._subplot_number,
projection=projection)
else:
return self.fig.add_subplot(self.rows, self.cols,
self._subplot_number)
def save(self, filename):
#self.fig.savefig(filename, bbox_inches='tight', pad_inches=0.1)
self.fig.savefig(filename)
def linear(self, title='', grid=True, style='o-', x_labels=None,
legends=True, ignore='', colors=None,
colormap=matplotlib.cm.PRGn):
if legends is None or legends is True:
legends = {header: header for header in self.data.headers}
subplot = self._get_new_subplot()
subplot.set_title(title)
subplot.grid(grid)
columns_to_plot = []
for header in set(self.data.headers) - set(ignore):
if header != x_labels and self.data.types[header] in (int, float):
columns_to_plot.append(header)
if colors is None:
color_range = linspace(0, 0.9, len(columns_to_plot))
colors = [colormap(i) for i in color_range]
for header in columns_to_plot:
subplot.plot(self.data[header], style, label=legends[header],
color=colors.pop(0))
if x_labels is not None:
subplot.set_xticklabels(self.data[x_labels])
subplot.legend()
def scatter(self, x_column, title='', grid=True, labels=True, legends=True,
style='o-', ignore='', colors=None,
colormap=matplotlib.cm.PRGn, order_by=None, ordering='asc',
x_label=None, y_lim=None, legend_location='upper center',
legend_box=(0.5, 2.2), y_label=''):
subplot = self._get_new_subplot()
subplot.set_title(title)
subplot.grid(grid)
if order_by is not None:
self.data.order_by(order_by, ordering)
if legends is True:
legends = {header: header for header in self.data.headers}
if self.data.types[x_column] in (datetime.date, datetime.datetime):
self.fig.autofmt_xdate()
if labels:
if x_label is None:
x_label = x_column
subplot.set_xlabel(x_label)
subplot.set_ylabel(y_label)
x_values = range(1, len(self.data[x_column]) + 1)
subplot.set_xlim(0, max(x_values) + 1)
columns_to_plot = []
for header in set(self.data.headers) - set(ignore):
if header != x_column and self.data.types[header] in (int, float):
columns_to_plot.append(header)
if colors is None:
color_range = linspace(0, 0.9, len(columns_to_plot))
colors = [colormap(i) for i in color_range]
for header in columns_to_plot:
if legends is None:
subplot.plot(x_values, self.data[header], style,
color=colors.pop(0))
else:
subplot.plot(x_values, self.data[header], style,
label=legends[header], color=colors.pop(0))
subplot.set_xticks(x_values)
subplot.set_xticklabels(self.data[x_column])
if y_lim is not None:
subplot.set_ylim(y_lim)
if legends is not None:
subplot.legend(loc=legend_location, bbox_to_anchor=legend_box)
self.fig.subplots_adjust(top=0.5, right=0.9)
def bar(self, title='', grid=True, count=None, bar_width=0.8, x_column='',
bar_start=0.5, bar_increment=1.0, legends=True,
x_rotation=0, colors=None, colormap=matplotlib.cm.PRGn,
y_label=None, y_lim=None, y_columns=None):
#.........这里部分代码省略.........
示例13: ascending
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import order_by [as 别名]
#!/usr/bin/env python
# coding: utf-8
# title = Ordering `Table` Data
#You can order your table's data with the method `Table.order_by`.
#You need to specify a column in which the ordering will be based on and
#optionally specify if the ordering will be ascending (default) or descending.
from outputty import Table
my_table = Table(headers=['First name', 'Last name'])
my_table.append({'First name': 'Álvaro', 'Last name': 'Justen'})
my_table.append({'First name': 'Renne'})
my_table.append(('Flávio', 'Amieiro'))
my_table.order_by('Last name')
print my_table