PMelan
PMelan

Reputation: 23

Opened Paradox File Using PypxLib And Need to Insert Data into Dataframe

I was successful in opening a paradox .db file using PyPxLib and now I am searching for some type of code to insert the rows into a Pandas dataframe.

    from pypxlib import Table


    table = Table('d:/Projects/Lakeport/Data/bbrptfav.db')

    try:
          for row in table:
                print(row)
    finally:
          table.close()

The resulting data prints out as follows:

    Row(Account Code='.5')
    Row(Account Code='01', Account Description='PLAN CHECK')
    Row(Account Code='02', Account Description='BUILDING PERMIT FEE')

I would like the resulting data to be inserted into a dataframe

Thank you

Upvotes: 0

Views: 311

Answers (1)

Timeless
Timeless

Reputation: 37747

Seems like the Table and the Row classes are roughly an OrderedDict. So, can you try this ?

df = pd.DataFrame(table, columns=table.fields.keys()) #or pd.DataFrame(table)
#or df = pd.DataFrame([dict(row) for row in table], columns=table.fields.keys())
#or df = pd.DataFrame([row.items() for row in table], columns=table.fields.keys())

This should give you the following DataFrame :

print(df)

  Account Code  Account Description
0           .5                  NaN
1           01           PLAN CHECK
2           02  BUILDING PERMIT FEE

Upvotes: 0

Related Questions