如何删除包含 alpha 值或整个 dbf 列的 dbf 行
How to delete dbf rows containing an alpha value or an entire dbf column
我想删除我的 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)
提前致谢
我认为这应该可行:
from simpledbf import Dbf5
dbf = Dbf5('file.dbf')
data = dbf.to_dataframe()
for row in range(len(data)):
Reg= data.loc[row,'Reg']
Prov = data.loc[row,'Prov']
if Reg =='knapford' or Prov =='knapford':
data.drop(index=row, axis=0, inplace=True)
其他脚本运行良好:
import dbf
with table as tab:
for record in dbf.Process(tab):
if record[1].strip()=='Knapford':
#print (record)
dbf.delete(record)
table.pack()
我想删除我的 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)
提前致谢
我认为这应该可行:
from simpledbf import Dbf5
dbf = Dbf5('file.dbf')
data = dbf.to_dataframe()
for row in range(len(data)):
Reg= data.loc[row,'Reg']
Prov = data.loc[row,'Prov']
if Reg =='knapford' or Prov =='knapford':
data.drop(index=row, axis=0, inplace=True)
其他脚本运行良好:
import dbf
with table as tab:
for record in dbf.Process(tab):
if record[1].strip()=='Knapford':
#print (record)
dbf.delete(record)
table.pack()