Skip to content

Instantly share code, notes, and snippets.

@jeffatennis
Forked from ryan-hill/dbf2DF.py
Created January 22, 2016 21:38
Show Gist options
  • Select an option

  • Save jeffatennis/42c3717220f649199591 to your computer and use it in GitHub Desktop.

Select an option

Save jeffatennis/42c3717220f649199591 to your computer and use it in GitHub Desktop.

Revisions

  1. Ryan Hill revised this gist Sep 18, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion dbf2DF.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,9 @@
    '''
    def dbf2DF(dbfile, upper=True): #Reads in DBF files and returns Pandas DF
    db = ps.open(dbfile) #Pysal to open DBF
    pandasDF = pd.DataFrame(db[:]) #Convert to Pandas DF
    d = {col: db.by_col(col) for col in db.header} #Convert dbf to dictionary
    #pandasDF = pd.DataFrame(db[:]) #Convert to Pandas DF
    pandasDF = pd.DataFrame(d) #Convert to Pandas DF
    if upper == True: #Make columns uppercase if wanted
    pandasDF.columns = map(str.upper, db.header)
    db.close()
  2. Ryan Hill created this gist Sep 16, 2015.
    15 changes: 15 additions & 0 deletions dbf2DF.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import pysal as ps
    import pandas as pd
    '''
    Arguments
    ---------
    dbfile : DBF file - Input to be imported
    upper : Condition - If true, make column heads upper case
    '''
    def dbf2DF(dbfile, upper=True): #Reads in DBF files and returns Pandas DF
    db = ps.open(dbfile) #Pysal to open DBF
    pandasDF = pd.DataFrame(db[:]) #Convert to Pandas DF
    if upper == True: #Make columns uppercase if wanted
    pandasDF.columns = map(str.upper, db.header)
    db.close()
    return pandasDF