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 b
As mmann1123 stated, you can use geopandas in order to read your dbf file. The Geopandas reads it even though it may or may not have geospatial data.
Assuming your data is only tabular data (no geographical coordinate on it), and you wish to read it and convert to a format which pandas library can read, I would suggest using geopandas.
Here is an example:
import geopandas as gpd
My_file_path_name = r'C:\Users\...file_dbf.dbf'
Table = gpd.read_file(Filename)
import pandas as pd
Pandas_Table = pd.DataFrame(Table)
Keys = list(Table.keys())
Keys.remove('ID_1','ID_2') # removing ID attributes from the Table keys list
Keys.remove('Date') # eventually you have date attribute which you wanna preserve.
DS = pd.melt(Pandas_Table,
id_vars =['ID_1','ID_2'], # accepts multiple filter/ID values
var_name='class_fito', # Name of the variable which will aggregate all columns from the Table into the Dataframe
value_name ='biomass (mg.L-1)' , # name of the variable in Dataframe
value_vars= Keys # parameter that defines which attributes from the Table are a summary of the DataFrame)
# checking your DataFrame:
type(DS) # should appear something like: pandas.core.frame.DataFrame