【发布时间】:2020-01-12 06:58:57
【问题描述】:
我想删除我的 dfb 上包含特定数据的一些行和列。
假设 dfb 的结构如下图所示,并且我想删除以 'knapford' 作为 'Prov' 的行和 'Reg' 列。
当我尝试遵循这个脚本时:
table = dbf.Table(wonderland.dbf).open(mode=dbf.READ_WRITE)
with table as tab:
print (table)
for record in dbf.Process(tab):
dbf.delete(record[0])
我收到此错误:
File "<ipython-input-4-d8feabfc9819>", line 4, in <module>
dbf.delete(record[0])
File "C:\Users\fassi\AppData\Local\Continuum\anaconda3\lib\site-packages\dbf\__init__.py", line 8349, in delete
if not template and record._meta.status == CLOSED:
AttributeError: 'int' object has no attribute '_meta'
我想到了这个其他建议,但我想知道它是否真的会删除该行的所有字段,只是一些特定的字段或所有记录!
table = dbf.Table(wonderland.dbf).open(mode=dbf.READ_WRITE)
with table as tab:
dbf.delete_fields(table, Reg)
for record in dbf.Process(tab):
if record[0].strip()=='Knapford': #since we've delete the Reg, Prov is becoming record[0]?
dbf.delete(record)
提前致谢
【问题讨论】:
标签: python delete-row dbf