简体   繁体   English

如何使用python将dbf表划分为两个或多个dbf表

[英]How to divide a dbf table to two or more dbf tables by using python

I have a dbf table. 我有一个dbf表。 I want to automatically divide this table into two or more tables by using Python. 我想使用Python自动将此表分为两个或多个表。 The main problem is, that this table consists of more groups of lines. 主要问题是,该表由更多行组成。 Each group of lines is divided from the previous group by empty line. 每组线与上一组用空行分开。 So i need to save each of groups to a new dbf table. 所以我需要将每个组保存到一个新的dbf表中。 I think that this problem could be solved by using some function from Arcpy package and FOR cycle and WHILE, but my brain cant solve it :D :/ My source dbf table is more complex, but i attach a simple example for better understanding. 我认为可以通过使用Arcpy包中的某些函数以及FOR cycle和WHILE来解决此问题,但是我的大脑无法解决它:D:/我的dbf表更加复杂,但是我附上了一个简单的示例以更好地理解。 Sorry for my poor english. 对不起,我英语不好。

Source dbf table: 源dbf表:

ID  NAME   TEAM
1   A      1
2   B      2
3   C      1
4   
5   D      2
6   E      3

I want get dbf1: 我想得到dbf1:

ID  NAME   TEAM
1   A      1
2   B      2
3   C      1

I want get dbf2: 我想得到dbf2:

ID  NAME   TEAM
1   D      2
2   E      3

Using my dbf package it could look something like this (untested): 使用我的dbf软件包,它可能看起来像这样(未经测试):

import dbf

source_dbf = '/path/to/big/dbf_file.dbf'
base_name = '/path/to/smaller/dbf_%03d'

sdbf = dbf.Table(source_dbf)
i = 1
ddbf = sdbf.new(base_name % i)

sdbf.open()
ddbf.open()
for record in sdbf:
    if not record.name:    # assuming if 'name' is empty, all are empty
        ddbf.close()
        i += 1
        ddbf = sdbf.new(base_name % i)
        continue
    ddbf.append(record)
ddbf.close()
sdbf.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM