Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

converting dictionary to pandas dataframe in python

I’m querying a API and pulling data that i need out of it. I then want to convert this to a pandas dataframe but not sure on best way to do it. I’ve got something that works but is very convoluted. The sample data below is a dictionary but this would really come from a API but it gets the point across.

invoice_header =        {
                        "VendorName" : "spinxy tester",
                        "VendorAddress" :"Unit 1 Anglesey Business Park argyle",
                        "CustomerName": "brick and mortar tavern",
                        "CustomerId": "73014207",
                        "CustomerAddress": "112 Main Street",
                        "CustomerAddressRecipient": "brick and mortar tavern",
                        "InvoiceId": "57953",
                        "InvoiceDate": "None",
                        "InvoiceTotal": "3474.0"
                        }
InvoiceNumber = "R20140.pdf"
all_invoices = {}
for key, value in invoice_header.items():
    all_invoices[key] = value    
all_invoices
df = pd.DataFrame(list(all_invoices.items()))
df = df.transpose()
df.columns = df.iloc[0]
df.drop(df.index[0], inplace=True)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I may be missing something here but is just this what you’re after?

df2 = pd.DataFrame([invoice_header])

Looks the same as df to me

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading