Pandas:将 dbf 表转换为数据框 [英] Pandas: transform a dbf Table into a dataframe
问题描述
我想读取 ArcGIS shapefile 的 dbf
文件并将其转储到 pandas
数据帧中.我目前正在使用 dbf 包.
I want to read a dbf
file of an ArcGIS shapefile and dump it into a pandas
dataframe. I am currently using the dbf package.
我显然能够将 dbf
文件加载为表格,但无法弄清楚如何解析它并将其转换为 Pandas 数据帧.有什么方法可以做到?
I have apparently been able to load the dbf
file as a Table, but have not been able to figure out how to parse it and turn it into a pandas dataframe. What is the way to do it?
这就是我被困的地方:
import dbf
thisTable = dbf.Table('C:\\Users\\myfolder\\project\\myfile.dbf')
thisTable.open(mode='read-only')
Python 将此语句作为输出返回,坦率地说,我不知道该怎么做:
Python returns this statement as output, which I frankly don't know what to make of:
dbf.ver_2.Table('C:\\Users\\myfolder\\project\\myfile.dbf', status='read-only')
编辑
我的原始 dbf
示例:
FID Shape E N
0 Point 90089.518711 -201738.245555
1 Point 93961.324059 -200676.766517
2 Point 97836.321204 -199614.270439
... ... ... ...
推荐答案
你应该看看 simpledbf:
In [2]: import pandas as pd
In [3]: from simpledbf import Dbf5
In [4]: dbf = Dbf5('test.dbf')
In [5]: df = dbf.to_dataframe()
这对我有用,有一个小示例 .dbf 文件.希望有所帮助.
This works for me with a little sample .dbf file. Hope that helps.
这篇关于Pandas:将 dbf 表转换为数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!