简体   繁体   English

Python WebServise HTTP响应文本JSON到数据框

[英]Python webservise http response text json to dataframe

How to have a http response JSON to Pandas DataFrame 如何对Pandas DataFrame使用HTTP响应JSON

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

'{\\n "Process": "[1, 1]"\\n}\\n' '{\\ 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. 如何使用此“过程”:将r.text中的“ [1,1]”传送到数据框,其中“ Process”为列名,每行中的值为1,1。 In this case , we can expect output dataFrame with one Column 'Process' and 2 rows 在这种情况下,我们可以期望输出dataFrame具有一列“ Process”和两行

You may use ast and json.loads 您可以使用astjson.loads

import ast
import json

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM