Python:在大 dbf (xbase) 文件中快速查询

标签 python performance python-3.x dbf xbase

我有一个很大的 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/

相关文章:

python 如何从这个列表中构建一个新列表

python - 如何使用 SQLAlchemy 保存 unicode?

c++ - 使用 ID 和数组( vector )的性能

python - Poetry 可以从 AWS CodeArtifact 添加包吗

python - 如何使用 Python 3.4.2 在 Windows 7 中安装 scipy

python - 如何从 C++ 返回 Python 类型的实例

python - 一起计算注释字段

android - android asynctask 总是这么慢吗

java - 插入排序比 shell 排序快得多

python - 从子图元素中获取已打印标签的列表,以避免图例中的重复输入