日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python pandas dataframe 转json_python-将嵌套的json转换为pandas dataframe

發布時間:2024/10/8 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python pandas dataframe 转json_python-将嵌套的json转换为pandas dataframe 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間: 2019-10-27 07:33:05

標簽:

pandas

python

我正在嘗試將嵌套的json數組轉換為 pandas dataframe .

列表格式的數據如下所示:

[{u'analysis': {u'active': u'Y',

u'dpv_cmra': u'N',

u'dpv_footnotes': u'AAN1',

u'dpv_match_code': u'D',

u'dpv_vacant': u'N',

u'footnotes': u'H#'},

u'candidate_index': 0,

u'components':

{u'city_name': u'City',

u'delivery_point': u'Variable',

u'delivery_point_check_digit': u'8',

u'plus4_code': u'Variable',

u'primary_number': u'Variable',

u'state_abbreviation': u'Variable',

u'street_name': u'Variable',

u'street_predirection': u'Variable',

u'street_suffix': u'Variable',

u'zipcode': u'Variable'},

u'delivery_line_1': u'Variable',

u'delivery_point_barcode': u'Variable',

u'input_id': u'Variable',

u'input_index': Variable,

u'last_line': u'Variable',

u'metadata':

{u'building_default_indicator': u'Variable',

u'carrier_route': u'Variable',

u'congressional_district': u'Variable',

u'county_fips': u'Variable',

u'county_name': u'Variable',

u'dst': True,

u'zip_type': u'Variable'}}],

有沒有建議我如何將其轉換為 dataframe 并處理空值?我嘗試使用try /除了處理丟失的值,但是我的 dataframe 然后由元組組成.

謝謝

最佳答案

pd.io.json內部有一個json_normalize函數.

d = {u'analysis': {u'active': u'Y', u'dpv_cmra': u'N', u'dpv_footnotes': u'AAN1', u'dpv_match_code': u'D', u'dpv_vacant': u'N', u'footnotes': u'H#'}, u'candidate_index': 0, u'components': {u'city_name': u'City', u'delivery_point': u'Variable', u'delivery_point_check_digit': u'8', u'plus4_code': u'Variable', u'primary_number': u'Variable', u'state_abbreviation': u'Variable', u'street_name': u'Variable', u'street_predirection': u'Variable', u'street_suffix': u'Variable', u'zipcode': u'Variable'}, u'delivery_line_1': u'Variable', u'delivery_point_barcode': u'Variable', u'input_id': u'Variable', u'input_index': u'Variable', u'last_line': u'Variable', u'metadata': {u'building_default_indicator': u'Variable', u'carrier_route': u'Variable', u'congressional_district': u'Variable', u'county_fips': u'Variable', u'county_name': u'Variable', u'dst': True, u'zip_type': u'Variable'}}

>>> pd.io.json.json_normalize(d)

analysis.active analysis.dpv_cmra analysis.dpv_footnotes analysis.dpv_match_code analysis.dpv_vacant analysis.footnotes candidate_index components.city_name components.delivery_point components.delivery_point_check_digit ... \

0 Y N AAN1 D N H# 0 City Variable 8 ...

input_id input_index last_line metadata.building_default_indicator metadata.carrier_route metadata.congressional_district metadata.county_fips metadata.county_name metadata.dst metadata.zip_type

0 Variable Variable Variable Variable Variable Variable Variable Variable True Variable

[1 rows x 29 columns]

總結

以上是生活随笔為你收集整理的python pandas dataframe 转json_python-将嵌套的json转换为pandas dataframe的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。