Search code examples
pythonpandasdataframearcgisdbf

Pandas: transform a dbf Table into a dataframe


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.

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?

This is where I am stuck at:

import dbf
thisTable = dbf.Table('C:\\Users\\myfolder\\project\\myfile.dbf')
thisTable.open(mode='read-only')

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')


EDIT

Sample of my original dbf:

FID   Shape    E              N
0     Point    90089.518711   -201738.245555
1     Point    93961.324059   -200676.766517
2     Point    97836.321204   -199614.270439
...   ...      ...            ...

Solution

  • You should have a look at 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()
    

    This works for me with a little sample .dbf file.