user2458922
user2458922

Reputation: 1721

Python webservise http response text json to dataframe

How to have a http response JSON to Pandas DataFrame

 r = requests.post(url, data=payload, headers=headers)
 r.text    

'{\n "Process": "[1, 1]"\n}\n'

How to take this "Process": "[1, 1]" from the r.text to a DataFrame with 'Process' as colunm name and 1,1 as valuess in each row. In this case , we can expect output dataFrame with one Column 'Process' and 2 rows

Upvotes: 0

Views: 122

Answers (1)

rafaelc
rafaelc

Reputation: 59274

You may use ast and json.loads

import ast
import json

x  = {k: ast.literal_eval(v) for k,v in json.loads(s).items()}
df = pd.DataFrame(x)

Upvotes: 1

Related Questions