0

I am passing a JSON object through a POST API into a flask app. The goal is to convert it to a single row pandas DF and pass it on for further processing.

the JSON payload is as follows:

{
  "ABC": "123",
  "DATE": "2020-01-01",
  "AMOUNT": "100",
  "IDENTIFIER": "12345"
} 

The output of data=flask.request.get_json() and print(data) is

{'ABC': '123', 'DATE': '2020-01-01', 'AMOUNT': '100','IDENTIFIER': '12345'} 

But when I do a pd.read_json(data) on it I get an error ValueError: Invalid file path or buffer object type: <class 'dict'> Any ideas on how to handle this? I need the output to be

ABC    DATE        AMOUNT    IDENTIFIER
123   2020-01-01   100        12345

Thanks!

1 Answer 1

1

Try this:

import pandas as pd

df = pd.DataFrame([data.values()], columns=data.keys())
print(df)

Output:

     ABC       DATE          AMOUNT   IDENTIFIER
 0   123       2020-01-01    100      12345
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.