当前位置: 首页>>代码示例>>Python>>正文


Python Table.add_column方法代码示例

本文整理汇总了Python中table.Table.add_column方法的典型用法代码示例。如果您正苦于以下问题:Python Table.add_column方法的具体用法?Python Table.add_column怎么用?Python Table.add_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在table.Table的用法示例。


在下文中一共展示了Table.add_column方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import add_column [as 别名]
	def apply(self, tables):

		columns = self.get_columns(tables)
		table = tables[0]
		
		measure_column = table[self['measure']]
		
		new_column_headers = []
		header_column = columns[0]
		start_row = 0
		end_row = table.rows()

		for v in header_column.data:
			if(not v in new_column_headers):
				new_column_headers.append(v)
		

		
		key_columns = filter(lambda x: not x.name in [measure_column.name, header_column.name], table)

		reduction = {}
		reduction_index = 0
		
		new_table = Table()
		
		for col in key_columns:
			new_table.add_column(col.name, {})
		
		#this name lookup is needed since table implementation changes names under certain circumstances
		name_lookup = {}
		for header in new_column_headers:
			col = new_table.add_column(header, {})
			name_lookup[header] = col.name
		
		
		for row in range(start_row, end_row):
			key = '*'.join([col[row] for col in key_columns])
			if(not reduction.has_key(key)):
				reduction[key] = reduction_index
				
				for col in key_columns:
					new_table[col.name][reduction_index] = col[row]
				
				reduction_index += 1

			index = reduction[key]
			header = header_column[row]
			measure = measure_column[row]
			
			
			new_table[name_lookup[header]][index] = measure


		table.clear()
		
		for col in new_table:
			table.insert_column(col, {})
开发者ID:tfmorris,项目名称:wrangler,代码行数:59,代码来源:unfold.py

示例2: test

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import add_column [as 别名]
def test():
	t = Table()


	c = t.add_column('data', {})
	
	

	
	c[0] = input_text
	
	# t[0][0] = 'a'
	# t[0][1] = 'b'
	# t[0][2] = 't'
	# t[0][3] = 'a'
	# t[0][4] = 'b'
	# t[0][5] = 't'
	# t[1][0] = 'red'
	# t[1][1] = 'red'
	# t[1][2] = 'red'
	# t[1][3] = 'blue'
	# t[1][4] = 'blue'
	# t[1][5] = 'blue'
	# t[2][0] = '1'
	# t[2][1] = '2'
	# t[2][2] = '3'
	# t[2][3] = '4'
	# t[2][4] = '5'
	# t[2][5] = '6'
	# 


 	# s = Filter()
 	# r = Row()
 	# i = Equals()
 	# i['value'] = 'red'
 	# i['lhs'] = 'color'
 	# # s['row'] = r
 	# r['conditions'] = [i]
 	# s.param('row', r)
	# print 'start'
	# 	t.debug()
	# 	
	w = DataWrangler()
	w.add(Split().param('column', ["data"]).param('table', 0).param('status', "active").param('drop', True).param('result', "row").param('update', False).param('insert_position', "right").param('row', None).param('on', "\n").param('before', None).param('after', None).param('ignore_between', None).param('which', 1).param('max', 0).param('positions', None).param('quote_character', None))
	w.add(Split().param('column', ["data"]).param('table', 0).param('status', "active").param('drop', True).param('result', "column").param('update', False).param('insert_position', "right").param('row', None).param('on', ",").param('before', None).param('after', None).param('ignore_between', None).param('which', 1).param('max', 0).param('positions', None).param('quote_character', None))
	w.add(Sort().param('column', ["split2"]).param('table', 0).param('status', "active").param('drop', False).param('direction', []).param('as_type', [Number().param('column', []).param('table', 0).param('status', "active").param('drop', False)]))
	w.add(Sort().param('column', ["split2"]).param('table', 0).param('status', "active").param('drop', False).param('direction', ["desc"]).param('as_type', [Number().param('column', []).param('table', 0).param('status', "active").param('drop', False)]))
	w.apply([t])



	# print 'end'
	t.debug()
	print t.rows(), t.cols()
开发者ID:tfmorris,项目名称:wrangler,代码行数:57,代码来源:test.py

示例3: gen_for_table

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import add_column [as 别名]
	def gen_for_table(self,tbl):
		"""Generates sql files for creating history tables and stored procedures.

		Calls functions for generating stored functions which differ for some cases. (embed tables, refuid columns)
		Stored functions means function for add object, set attribute, get attribute, get object data, get list of instances and functions for diffing of versions.
		For templated tables are generated stored functions to get resolved data or resolved data with its origin.
		"""
		# select col info
		columns = self.plpy.execute(self.column_str % tbl)
		att_types = self.plpy.execute(self.att_type_str % tbl)
		self.atts[tbl] = dict(att_types)
		self.refs[tbl] = list()

		# create table obj
		table = Table(tbl)

		# add columns
		for col in columns[:]:
			table.add_column(col[0],col[1])

		# add pk constraints
		constraints = self.plpy.execute(self.pk_str % tbl)
		for col in constraints[:]:
			table.add_pk(col[0],col[1])

		record = self.plpy.execute(self.refers_to_set_info_str % {'tbl': tbl})
		table.refers_to_set = list()
		if len(record) > 0:
			for row in record:
				table.refers_to_set.append(row[0])
			self.refers_to_set[tbl] = table.refers_to_set

		# add fk constraints
		fkconstraints = self.plpy.execute(self.fk_str % tbl)
		for col in fkconstraints[:]:
			table.add_fk(col[0],col[1],col[2],col[3])
			relName = col[0]
			while relName in self.relFromTbl:
				#check if relation if this name exists
				#and add suffix to it
				relName = relName + "_XXX"
			self.relFromTbl[relName] = tbl
			self.relFromCol[relName] = col[1]
			self.relToTbl[relName] = col[2]

			# if there is a reference, change int for identifier'
			if col[1] not in table.refers_to_set:
				self.atts[tbl][col[1]] = 'identifier'
			prefix = col[0][0:7]
			prefixForSet = col[0][0:5]
			if prefix == "rembed_":
				self.embed[tbl] = col[1]
				self.embedNames[relName] = tbl
			elif prefix == "rconta_":
				self.composition[tbl] = col[1]
				self.containsNames[relName] = tbl
			elif prefix == "rcoble_":
				self.containableNames[relName] = tbl
			elif prefix == "rtempl_":
				self.template[tbl] = col[2]
				self.templateNames[relName] = tbl
			elif prefix == "rrefer_" or prefixForSet == "rset_":
				self.refs[tbl].append(col[1])
				self.refNames[relName] = tbl

		embed_into_rec = self.plpy.execute(self.embed_into_str % tbl)
		table.embed_column = ""
		for row in embed_into_rec:
			table.embed_column = row[0]

		refuid_rec = self.plpy.execute(self.refuid_columns_str % tbl)
		table.refuid_columns = dict()
		for row in refuid_rec:
			table.refuid_columns[row[0]] = row[1]

		record = self.plpy.execute(self.composition_str % tbl)
		table.contains = list()
		for row in record:
			table.contains.append(row[0])

		if tbl in self.templates:
			templated_table = self.templates[tbl]
			refuid_rec = self.plpy.execute(self.refuid_columns_str % templated_table)
			for row in refuid_rec:
				if row[0] not in table.refuid_columns:
					table.refuid_columns[row[0]] = row[1]

		table.validate();

		# generate sql
		self.table_sql.write(table.gen_hist())

		self.fks = self.fks + (table.gen_fks())
		#get dictionary of colname and reftable, which uid colname references
		#cols_ref_uid = table.get_cols_reference_uid()
		for col in columns[:]:
			if (col[0] in table.refuid_columns):
				reftable = table.refuid_columns[col[0]]
				if col[0] in table.refers_to_set:
					self.fn_sql.write(table.gen_set_refuid_set(col[0], reftable))
#.........这里部分代码省略.........
开发者ID:jktjkt,项目名称:deska,代码行数:103,代码来源:schema.py


注:本文中的table.Table.add_column方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。