本文整理汇总了Python中journalism.Table类的典型用法代码示例。如果您正苦于以下问题:Python Table类的具体用法?Python Table怎么用?Python Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Table类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_by_preserves_rows
def test_order_by_preserves_rows(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table.order_by(lambda r: r['one'])
table3 = table2.order_by(lambda r: r['one'])
self.assertIsNot(table._data[0], table2._data[0])
self.assertIs(table2._data[0], table3._data[0])
示例2: test_where_preserves_rows
def test_where_preserves_rows(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table.where(lambda r: r['one'] == 1)
table3 = table2.where(lambda r: r['one'] == 1)
self.assertIsNot(table._data[0], table2._data[0])
self.assertIs(table2._data[0], table3._data[0])
示例3: analyse_insights
def analyse_insights():
"""
generate reports from insights data
"""
column_types = (date_type, number_type, number_type, number_type, number_type, number_type, boolean_type, text_type, text_type, text_type, text_type, boolean_type, text_type, text_type)
with open('www/live-data/insights.csv') as f:
rows = list(csv.reader(f))
column_names = rows.pop(0)
table = Table(rows, column_types, column_names)
summary_definition = list(itertools.product(FACEBOOK_METRICS, SUMMARY_TYPES))
summary = table.aggregate('provider_type', summary_definition)
count_grand_total = summary.columns['provider_type_count'].sum()
summary = summary.compute('provider_type_count_pct', number_type,
lambda x: (x['provider_type_count']/count_grand_total) * 100)
summary = summary.order_by('provider_type')
_write_summary_csv(summary, 'www/live-data/insights_summary.csv')
for metric in FACEBOOK_METRICS:
_generate_insights_histograms(metric, table, summary)
示例4: analyse_photo_efforts
def analyse_photo_efforts():
column_types = (number_type, text_type, text_type, text_type, boolean_type)
with open('www/live-data/photo_efforts.csv') as f:
rows = list(csv.reader(f))
column_names = rows.pop(0)
table = Table(rows, column_types, column_names)
homepage_summary = table.aggregate('on_homepage', (('duration', 'sum'),))
count_grand_total = homepage_summary.columns['on_homepage_count'].sum()
homepage_summary = homepage_summary.compute('on_homepage_count_pct', number_type,
lambda x: (x['on_homepage_count']/count_grand_total) * 100)
count_grand_total = homepage_summary.columns['duration_sum'].sum()
homepage_summary = homepage_summary.compute('duration_sum_pct', number_type,
lambda x: (x['duration_sum']/count_grand_total) * 100)
_write_summary_csv(homepage_summary, 'www/live-data/homepage_summary.csv')
contribution_summary = table.aggregate('contribution', (('duration', 'sum'),))
contribution_summary = contribution_summary.order_by('contribution_count', reverse=True)
contribution_summary = contribution_summary.compute('contribution_count_pct', number_type,
lambda x: (x['contribution_count']/count_grand_total) * 100)
contribution_summary = contribution_summary.compute('duration_sum_pct', number_type,
lambda x: (x['duration_sum']/count_grand_total) * 100)
_write_summary_csv(contribution_summary, 'www/live-data/contribution_summary.csv')
示例5: test_limit_preserves_rows
def test_limit_preserves_rows(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table.limit(2)
table3 = table2.limit(2)
self.assertIsNot(table._data[0], table2._data[0])
self.assertIs(table2._data[0], table3._data[0])
示例6: test_aggregeate_bad_column
def test_aggregeate_bad_column(self):
table = Table(self.rows, self.column_types, self.column_names)
with self.assertRaises(ColumnDoesNotExistError):
table.aggregate('bad', (('one', 'sum'), ))
with self.assertRaises(ColumnDoesNotExistError):
table.aggregate('two', (('bad', 'sum'), ))
示例7: test_column_names_immutable
def test_column_names_immutable(self):
column_names = ['one', 'two', 'three']
table = Table(self.rows, self.column_types, column_names)
column_names[0] = 'five'
self.assertEqual(table.get_column_names()[0], 'one')
示例8: test_order_by_reverse
def test_order_by_reverse(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.order_by(lambda r: r['two'], reverse=True)
self.assertEqual(len(new_table.rows), 3)
self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a'))
self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b'))
self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c'))
示例9: test_where
def test_where(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.where(lambda r: r['one'] in (2, None))
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 2)
self.assertSequenceEqual(new_table.rows[0], (2, 3, 'b'))
self.assertSequenceEqual(new_table.columns['one'], (2, None))
示例10: test_limit
def test_limit(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.limit(2)
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 2)
self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a'))
self.assertSequenceEqual(new_table.columns['one'], (1, 2))
示例11: test_compute_creates_rows
def test_compute_creates_rows(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table.compute('new2', self.number_type, lambda r: r['one'])
table3 = table2.compute('new3', self.number_type, lambda r: r['one'])
self.assertIsNot(table._data[0], table2._data[0])
self.assertNotEqual(table._data[0], table2._data[0])
self.assertIsNot(table2._data[0], table3._data[0])
self.assertNotEqual(table2._data[0], table3._data[0])
self.assertSequenceEqual(table._data[0], (1, 4, 'a'))
示例12: test_limit_step_only
def test_limit_step_only(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.limit(step=2)
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 2)
self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a'))
self.assertSequenceEqual(new_table.rows[1], (None, 2, 'c'))
self.assertSequenceEqual(new_table.columns['one'], (1, None))
示例13: test_limit_slice_negative
def test_limit_slice_negative(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.limit(-2, step=-1)
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 2)
self.assertSequenceEqual(new_table.rows[0], (2, 3, 'b'))
self.assertSequenceEqual(new_table.rows[1], (1, 4, 'a'))
self.assertSequenceEqual(new_table.columns['one'], (2, 1))
示例14: test_pearson_correlation_zero
def test_pearson_correlation_zero(self):
rows = (
(-1, 3, 'a'),
(0, 3, 'b'),
(1, 3, 'c')
)
table = Table(rows, self.column_types, self.column_names)
self.assertEqual(table.pearson_correlation('one', 'two'), Decimal('0'))
示例15: test_fork_preserves_data
def test_fork_preserves_data(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table._fork(table.rows)
self.assertIs(table.rows[0], table2._data[0])
self.assertIs(table.rows[1], table2._data[1])
self.assertIs(table.rows[2], table2._data[2])
self.assertIs(table.rows[0], table2.rows[0])
self.assertIs(table.rows[1], table2.rows[1])
self.assertIs(table.rows[2], table2.rows[2])