第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何將以下 json 文件轉(zhuǎn)換為數(shù)據(jù)框?

如何將以下 json 文件轉(zhuǎn)換為數(shù)據(jù)框?

狐的傳說 2023-02-22 13:55:48
我是 Python 新手,不知道如何將以下 JSON 數(shù)據(jù)轉(zhuǎn)換為 CSV 格式。非常感謝任何可以提供幫助的人!JSON數(shù)據(jù)是:{ "Hotel": [  {   "name": "Concorde Hotel New York",   "Reviewer": [    {     "name": "Serje J",     "Title": "Didn't make it but hope to soon",     "Title_url": "https://www.tripadvisor.com/ShowUserReviews-g60763-d14040955-r751642278-Concorde_Hotel_New_York-New_York_City_New_York.html",     "Description": "I was scheduled to stay here in March which unfortunately didn't happen due to COVID-19. I was forced to cancel my arrangements, however I was so impressed by the courtesy and promptitude with which Concorde staff arranged my cancellation and refund. When all this madness is behind us I will certainly be rebooking with this hotel.",     "Location": "Melbourne, Australia",     "Date": "Date of stay: March 2020",     "Rating": "ui_bubble_rating bubble_50"    },    {     "name": "John Schueler",     "Title": "Beautiful Modern Rooms in East MidTown",     "Title_url": "https://www.tripadvisor.com/ShowUserReviews-g60763-d14040955-r751405066-Concorde_Hotel_New_York-New_York_City_New_York.html",     "Description": "The lobby is under construction but the rooms are fresh, modern and very nicely appointed. The bathrooms are large and very nice. Only complaint was the wifi was weak in the room - which could be due to the construction disruption. Great location for sites and restaurants. Room was very quiet!",     "Location": "Beaufort, South Carolina",     "Date": "Date of stay: March 2020",     "Rating": "ui_bubble_rating bubble_40"    }   ]  } ]}
查看完整描述

2 回答

?
大話西游666

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊

  1. json_normalize將 pandas 中的記錄展平/結(jié)構(gòu)化

  2. 為了美化,將Hotel.name移到第一列

  3. 使用 pandas 功能輸出為 CSV

import pandas as pd

js = {

 "Hotel": [

  {

   "name": "Concorde Hotel New York",

   "Reviewer": [

    {

     "name": "Serje J",

     "Title": "Didn't make it but hope to soon",

     "Title_url": "https://www.tripadvisor.com/ShowUserReviews-g60763-d14040955-r751642278-Concorde_Hotel_New_York-New_York_City_New_York.html",

     "Description": "I was scheduled to stay here in March which unfortunately didn't happen due to COVID-19. I was forced to cancel my arrangements, however I was so impressed by the courtesy and promptitude with which Concorde staff arranged my cancellation and refund. When all this madness is behind us I will certainly be rebooking with this hotel.",

     "Location": "Melbourne, Australia",

     "Date": "Date of stay: March 2020",

     "Rating": "ui_bubble_rating bubble_50"

    },

    {

     "name": "John Schueler",

     "Title": "Beautiful Modern Rooms in East MidTown",

     "Title_url": "https://www.tripadvisor.com/ShowUserReviews-g60763-d14040955-r751405066-Concorde_Hotel_New_York-New_York_City_New_York.html",

     "Description": "The lobby is under construction but the rooms are fresh, modern and very nicely appointed. The bathrooms are large and very nice. Only complaint was the wifi was weak in the room - which could be due to the construction disruption. Great location for sites and restaurants. Room was very quiet!",

     "Location": "Beaufort, South Carolina",

     "Date": "Date of stay: March 2020",

     "Rating": "ui_bubble_rating bubble_40"

    }

   ]

  }

 ]

}

# use provided functionality to flatten and normalise data

df = pd.json_normalize(js, record_path=["Hotel","Reviewer"], meta=[["Hotel","name"]])

# Hotel.name logically should be 1st column, move it

df.insert(0, "Hotel.name", df.pop("Hotel.name"))

# make it a CSV....

df.to_csv(index=False)


查看完整回答
反對 回復(fù) 2023-02-22
?
墨色風(fēng)雨

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊

首先,我建議您始終將 Json 粘貼到查看器中。這樣您就可以輕松地可視化文件結(jié)構(gòu)。


然后,將您提供的示例保存為file.json,只需幾行代碼即可獲得:


import pandas as pd


file = pd.read_json("file.json")


temp = file['Hotel'][0]['Reviewer']


df = pd.DataFrame.from_dict(temp)


df['hotel'] = file['Hotel'][0]['name']


>> df


            name  ...                    hotel

0        Serje J  ...  Concorde Hotel New York

1  John Schueler  ...  Concorde Hotel New York


查看完整回答
反對 回復(fù) 2023-02-22
  • 2 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號