Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: transform a dbf Table into a dataframe

Tags:

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 ...   ...      ...            ... 
like image 430
FaCoffee Avatar asked Jan 27 '17 16:01

FaCoffee


People also ask

How do I read a DBF file in Python?

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.

How do you convert a data set into a data frame?

You can convert the sklearn dataset to pandas dataframe by using the pd. Dataframe(data=iris. data) method.

How do I convert Dtypes to pandas?

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


1 Answers

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.

like image 102
Fabio Lamanna Avatar answered Sep 18 '22 21:09

Fabio Lamanna