本文整理汇总了Python中journalism.Table.reject方法的典型用法代码示例。如果您正苦于以下问题:Python Table.reject方法的具体用法?Python Table.reject怎么用?Python Table.reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类journalism.Table
的用法示例。
在下文中一共展示了Table.reject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import reject [as 别名]
with open('examples/realdata/Datagov_FY10_EDU_recp_by_State.csv') as f:
# Skip headers
f.next()
f.next()
f.next()
rows = list(csv.reader(f))
# Trim cruft off end
rows = rows[:-2]
# Create the table
table = Table(rows, COLUMN_TYPES, COLUMN_NAMES, cast=True)
# Remove Phillipines and Puerto Rico
states = table.reject(lambda r: r['state_abbr'] in ['PR', 'PH'])
# Sum total of all states
print 'Total of all states: %i' % states.columns['total'].sum()
# Sort state total, descending
sort_by_total_desc = states.sort_by('total', reverse=True)
# Grab just the top 5 states
top_five = sort_by_total_desc.rows[0:5]
for i, row in enumerate(top_five):
print '# %i: %s %i' % (i, row['state'], row['total'])
# Grab just the bottom state
last_place = sort_by_total_desc.rows[-1]