[英]How can I make pretty dataframe using json file in python?
I've try to save the data that I received from Open API.我尝试保存从 Open API 收到的数据。
import requests
import pandas as pd
import json
from pandas import DataFrame
def Bring_API():
url = "api_url/authenticate key/options"
response = requests.get(url)
data = response.json()
print(data)
Bring_API()
When I receive the API information from the server, it shows me the JSON file, but it's very dizzy.当我收到来自服务器的 API 信息时,它向我显示了 JSON 文件,但是很晕。 Like below.如下所示。
{"COOKRCP01":{"total_count":"1318","row":[{"RCP_PARTS_DTLS":"sweet potato soup\nsweet potato 100g, sugar 2g, rice powder 3g,water 200ml", "RCP_WAY2":"boil","MANUAL_IMG20":"","MANUAL20":"","RCP_SEQ":"17","INFO_NA":"68","INFO_WGT":"","INFO_PRO":"3","MANUAL_IMG13":"","MANUAL_IMG14":"","MANUAL_IMG15":"","MANUAL_IMG16":"","MANUAL_IMG10":"","MANUAL_IMG11":"","MANUAL_IMG12":"","MANUAL_IMG17":"","MANUAL_IMG18":"","MANUAL_IMG19":"","INFO_FAT":"6","HASH_TAG":"","MANUAL_IMG02":"http://www.foodsafetykorea.go.kr/uploadimg/cook/20_00017_2.png","MANUAL_IMG03":"http://www.foodsafetykorea.go.kr/uploadimg/cook/20_00017_3.png","RCP_PAT2":"dessert","MANUAL_IMG04":"","MANUAL_IMG05":"","MANUAL_IMG01":"http://www.foodsafetykorea.go.kr/uploadimg/cook/20_00017_1.png","MANUAL01":"1. wash and cut.","ATT_FILE_NO_MK":"http://www.foodsafetykorea.go.kr/uploadimg/cook/10_00017_1.png","MANUAL_IMG06":"","MANUAL_IMG07":"","MANUAL_IMG08":"","MANUAL_IMG09":"","MANUAL08":"","MANUAL09":"","MANUAL06":"","MANUAL07":"","MANUAL04":"4. mix.","MANUAL05":"","MANUAL02":"2. boil it.","MANUAL03":"3. make","ATT_FILE_NO_MAIN":"http://www.foodsafetykorea.go.kr/uploadimg/cook/10_00017_2.png","MANUAL11":"","MANUAL12":"","MANUAL10":"","INFO_CAR":"35","MANUAL19":"","INFO_ENG":"205","MANUAL17":"","MANUAL18":"","RCP_NM":"sweet potato soup","MANUAL15":"","MANUAL16":"","MANUAL13":"","MANUAL14":""}],"RESULT":{"MSG":"sucess.","CODE":"INFO-000"}}}
So I try to make it clear, using the pandas dataframe module.所以我试着说清楚,使用 pandas dataframe 模块。
df = pd.read_json (r'C:\Users\admin\Desktop\1.json')
print (df)
However when I doing it, It was very different from what I thought.但是,当我这样做时,它与我的想法非常不同。
COOKRCP01
RESULT {'MSG': 'Success.', 'CODE': 'INFO-000'}
row [{'RCP_PARTS_DTLS': 'Sweet Potato
Sweet Potato 100g, Sugar 2...
total_count 1318
Why can't I make the result like other pretty dataframe.为什么我不能像其他漂亮的 dataframe 那样制作结果。 ex)前任)
0 'RCP_PARTS_DTLS' 'RCP_NM'
1 Sweet potato,sugar,rice powder SWeet Potato Soup
Can someone teach me how to eliminate the key and value in json file (or sort specific key and value from json file) what module should I use?有人可以教我如何消除 json 文件中的键和值(或从 json 文件中对特定键和值进行排序)我应该使用什么模块?
Maybe you can load it as a JSON file.也许您可以将其加载为 JSON 文件。 Using json module, json.load()使用 json 模块,json.load()
and then passing to pandas dataframe only what you want as a table:然后仅将您想要的表格传递给 pandas dataframe :
df = pd.DataFrame(data["COOKRCP01"]["row"])
LS RCP_WAY2... MANUAL13 MANUAL14 0 sweet potato soup\nsweet potato 100g, sugar 2g... boil... LS RCP_WAY2... MANUAL13 MANUAL14 0 红薯汤\n红薯100g,糖2g...煮...
[1 rows x 54 columns] [1 行 x 54 列]
You can Transpose it to get:您可以转置它以获得:
print (df.T)
RCP_PARTS_DTLS sweet potato soup\nsweet potato 100g, sugar 2g... RCP_WAY2 boil MANUAL_IMG20 RCP_PARTS_DTLS 红薯汤\n红薯 100g,糖 2g... RCP_WAY2 煮 MANUAL_IMG20
MANUAL20手册20
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.