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


Python Table.append_row方法代码示例

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


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

示例1: load_table

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

    seen_header = False
    for line in file(filename):
        if not seen_header:
            seen_header = True
            continue

        line = line.rstrip("\n")
        (id, status, price, genres, policy, countries) = line.split("\t")

        def split_ints(commasep):
            if commasep == '':
                return set()
            return set([int(s) for s in commasep.split(",")])

        t.append_row(
            id,
            {
            'status': status,
            'price': int(float(price)*100),
            'genre': split_ints(genres),
            'policy': policy,
            'country': split_ints(countries)
            })

    return t
开发者ID:toddlipcon,项目名称:bitserve,代码行数:30,代码来源:tsv_test.py

示例2: result

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import append_row [as 别名]
    def result(self):
        """ Perform the query, and return the result as a Table object """

        BaseQuery.logger.log( "With arguments: " + str(self.arguments) )
        BaseQuery.logger.log( "Running query: \n" + str(self.complete_query) )

        cursor = self.db_connection.cursor()

        start_time = time.time()
        cursor.execute( self.complete_query ) 
        self.elapsed_time = time.time() - start_time

        BaseQuery.logger.log( str(self.elapsed_time) + " seconds" )

        results_table = Table()
        
        for col in cursor.description:
            results_table.append_column( col[0] )

        row = cursor.fetchone()
        while row:
            results_table.append_row( [self.output_clean_function(i) for i in row] )
            row = cursor.fetchone()

        self.rows_fetched = len(results_table) 

        BaseQuery.logger.log( str(self.rows_fetched) + " rows fetched" )

        return results_table
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:31,代码来源:query.py

示例3: load_table

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import append_row [as 别名]
    def load_table(self, name, path, columns):
        t = Table()
        seen_header = False

        # Find the pk and other fields
        pk = None
        fields = []
        idx = 0
        for (idx, colspec) in enumerate(columns):
            colspec.idx = idx

            # attach a convert function
            colspec.convert = self.CONVERT_FUNS[colspec.type]

            if colspec.is_primary_key:
                if pk:
                    raise TApplicationException(
                        "too many pks: %s and %s" % (pk.name, colspec.name)
                        )
                pk = colspec
            else:
                fields.append(colspec)

        print "Loading table %s from %s" % (name, path)
        for (lineno, line) in enumerate(file(path)):
            if not seen_header:
                seen_header = True
                continue

            linefields = line.rstrip("\n").split("\t")
            data = {}
            for field in fields:
                data[field.name] = field.convert(linefields[field.idx])
            pk_val = pk.convert(linefields[pk.idx])

            t.append_row(pk_val, data)

            if lineno % 1000 == 0:
                print "loaded %d lines" % lineno

        self.tables[name] = t
        print "Finished loading %d rows into table %s" % (t.num_rows, name)
        return t.num_rows
开发者ID:toddlipcon,项目名称:bitserve,代码行数:45,代码来源:bitserve.py

示例4: sin_clean

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import append_row [as 别名]
        for row in table.row_maps():
            clean_attempt = ""
            if group_name == 'sin':
                clean_attempt = sin_clean( row[column] )
            if group_name == 'dates':
                clean_attempt = date_clean( row[column] )
            if group_name == 'semesters':
                clean_attempt = semester_clean( row[column] )
            translation_table[ row[ column ] ] = clean_attempt
        if os.path.exists( group_name + ".csv" ):
            t = Table.from_csv( group_name + ".csv" ) 
            for row in t.rows:
                if row[0] in translation_table and translation_table[ row[0] ] != "" and row[1] == "":
                    pass
                else:
                    translation_table[ row[0] ] = row[1]
        column_index = table.headers.index(column)
        for row in output_table.rows:
            if row[column_index] in translation_table and translation_table[row[column_index]] != "":
                row[column_index] = translation_table[row[column_index]]

    t = Table()

    t.append_column( group_name )
    t.append_column( "canonical" )
    for key, value in translation_table.iteritems():
        t.append_row( [ key, value ] )
    t.to_csv( group_name + ".csv")

output_table.to_csv( "output.csv" )
开发者ID:avacariu,项目名称:coursys,代码行数:32,代码来源:cleaner.py


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