小编spa*_*ine的帖子

展平双嵌套JSON

我试图压扁一个看起来像这样的JSON文件:

{
"teams": [
  {
    "teamname": "1",
    "members": [
      {
        "firstname": "John", 
        "lastname": "Doe",
        "orgname": "Anon",
        "phone": "916-555-1234",
        "mobile": "",
        "email": "john.doe@wildlife.net"
      },
      {
        "firstname": "Jane",
        "lastname": "Doe",
        "orgname": "Anon",
        "phone": "916-555-4321",
        "mobile": "916-555-7890",
        "email": "jane.doe@wildlife.net"
      }
    ]
  },
  {
    "teamname": "2",
    "members": [
      {
        "firstname": "Mickey",
        "lastname": "Moose",
        "orgname": "Moosers",
        "phone": "916-555-0000",
        "mobile": "916-555-1111",
        "email": "mickey.moose@wildlife.net"
      },
      {
        "firstname": "Minny",
        "lastname": "Moose",
        "orgname": "Moosers",
        "phone": "916-555-2222",
        "mobile": "",
        "email": "minny.moose@wildlife.net"
      }
    ]
  }       
]
Run Code Online (Sandbox Code Playgroud)

}

我希望将其导出到excel表.我目前的代码是这样的:

from pandas.io.json import …
Run Code Online (Sandbox Code Playgroud)

python excel json dictionary pandas

7
推荐指数
2
解决办法
7692
查看次数

如何使用平面数据表中的嵌套记录构建JSON文件?

我正在寻找一种Python技术来从pandas数据框中的平面表构建嵌套的JSON文件.例如,pandas数据框表如何如下:

teamname  member firstname lastname  orgname         phone        mobile
0        1       0      John      Doe     Anon  916-555-1234                 
1        1       1      Jane      Doe     Anon  916-555-4321  916-555-7890   
2        2       0    Mickey    Moose  Moosers  916-555-0000  916-555-1111   
3        2       1     Minny    Moose  Moosers  916-555-2222
Run Code Online (Sandbox Code Playgroud)

被采用并导出为看起来像这样的JSON:

{
"teams": [
{
"teamname": "1",
"members": [
  {
    "firstname": "John", 
    "lastname": "Doe",
    "orgname": "Anon",
    "phone": "916-555-1234",
    "mobile": "",
  },
  {
    "firstname": "Jane",
    "lastname": "Doe",
    "orgname": "Anon",
    "phone": "916-555-4321",
    "mobile": "916-555-7890",
  }
]
},
{
"teamname": "2",
"members": [
  {
    "firstname": …
Run Code Online (Sandbox Code Playgroud)

python json nested pandas

7
推荐指数
1
解决办法
1694
查看次数

标签 统计

json ×2

pandas ×2

python ×2

dictionary ×1

excel ×1

nested ×1