我有一个很大的 DBF 文件 (~700MB)。我只想使用 python 脚本从中选择几行。我已经看到 dbfpy 是一个很好的模块,可以打开这种类型的数据库,但目前我还没有找到任何查询功能。遍历 python 中的所有元素实在是太慢了。
我可以在合理的时间内用 python 做我想做的事吗?
最佳答案
使用 my dbf module您可以创建临时索引,然后使用这些索引进行搜索:
import dbf
table = dbf.Table('big.dbf')
index = table.create_index(lambda rec: rec.field) # field should be actual field name
records = index.search(match=('value',))
创建索引可能需要几秒钟,但之后的搜索速度非常快。
关于Python:在大 dbf (xbase) 文件中快速查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2373086/