i need to format the contents of a Json file in a certain format in a pandas DataFrame so that i can run pandassql to transform the data and run it through a scoring model.
file=C:\scoring\u model\json.js("文件"的内容如下)
{
"response":{
"version":"1.1",
"token":"dsfgf",
"body":{
"customer":{
"customer_id":"1234567",
"verified":"true"
},
"contact":{
"email":"mr@abc.com",
"mobile_number":"0123456789"
},
"personal":{
"gender": "m",
"title":"Dr.",
"last_name":"Muster",
"first_name":"Max",
"family_status":"single",
"dob":"1985-12-23",
}
}
}
我需要数据框看起来像这样(显然,同一行上的所有值,都试图为这个问题设置尽可能好的格式):
version | token | customer_id | verified | email | mobile_number | gender |
1.1 | dsfgf | 1234567 | true | mr@abc.com | 0123456789 | m |
title | last_name | first_name |family_status | dob
Dr. | Muster | Max | single | 23.12.1985
我研究了关于这个主题的所有其他问题,try 了各种方法将Json文件加载到Pandas 中
`with open(r'C:\scoring_model\json.js', 'r') as f:`
c = pd.read_json(f.read())
`with open(r'C:\scoring_model\json.js', 'r') as f:`
c = f.readlines()
我试过pd.此解决方案中的Panel()Python Pandas: How to split a sorted dictionary in a column of a dataframe
[yo=f.readlines()]中的dataframe results考虑try 根据("")拆分每个单元格的内容,并找到一种方法将拆分的内容放入不同的列中,但目前为止运气不佳.非常感谢您的专业知识.提前谢谢你.