Pandas: transform a dbf Table into a dataframe

后端 未结 5 1053
后悔当初
后悔当初 2021-02-12 15:59

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

5条回答
  •  感动是毒
    2021-02-12 16:27

    How about using dbfpy? Here's an example that shows how to load a dbf with 3 columns into a dataframe:

    from dbfpy import dbf
    import pandas as pd
    
    df = pd.DataFrame(columns=('tileno', 'grid_code', 'area'))
    db = dbf.Dbf('test.dbf')
    for rec in db:
        data = []
        for i in range(len(rec.fieldData)):
            data.append(rec[i])
        df.loc[len(df.index)] = data
    db.close()
    

    If necessary, you could find out the column names from db.fieldNames.

提交回复
热议问题