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 ... ... ... ...
How to read it using python ? “dbfread” is the library available in python to read dbf files. This library reads DBF files and returns the data as native Python data types for further processing. dbfread requires python 3.2 or 2.7.
You can convert the sklearn dataset to pandas dataframe by using the pd. Dataframe(data=iris. data) method.
In order to convert data types in pandas, there are three basic options: Use astype() to force an appropriate dtype. Create a custom function to convert the data. Use pandas functions such as to_numeric() or to_datetime()
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. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With