'Format group by in python

In Python 1

I want format to my data json something like this:

data: [
    {
        'sample_id': {
            name: 'JS195-A'
        },
        '10_um': {
            'id': 1
            image: '/abc/abc2.jpg',
            status: 1-Ok / 2-NG,
            comment: 'abv'
        },
        '20_um': {
            'id': 1
            image: '/abc/abc2.jpg',
            status: 0-None / 1-Ok / 2-NG,
            comment: 'abv'
        },
        '30_um':  {
            image: '/abc/abc2.jpg',
            status: 1-Ok / 2-NG,
            comment: 'abv'
        }
    },
    {
        'id': 1
        'sample_id': {
            name: 'JS195-b'
        },
        '10_um': {
            image: '/abc/abc2.jpg',
            status: 1-Ok / 2-NG,
            comment: 'abv'
        },
        '20_um': {
            image: '/abc/abc2.jpg',
            status: 1-Ok / 2-NG,
            comment: 'abv'
        },
        '30_um':  {
            image: '/abc/abc2.jpg',
            status: 1-Ok / 2-NG,
            comment: 'abv'
        }
    }
]

Sample_id will be Columns 1 and group same Name Value of Columns Focus will be group same value 10,20,30 from database

Result I want:

2

Python



Solution 1:[1]

This is my first data

"data": [
{
  "id": 2,
  "sample_id": "JS195-A",
  "exposure": "",
  "focus": "20",
  "via_diameter_um": "2",
  "sem_conditions": "",
  "file_name": "work.jpg",
  "file_path": "file:///D:/images/",
  "status": null,
  "comment": null
},
{
  "id": 3,
  "sample_id": "JS195-B",
  "exposure": "",
  "focus": "20",
  "via_diameter_um": "3",
  "sem_conditions": "",
  "file_name": "forest.jpg",
  "file_path": "file:///D:/images/",
  "status": null,
  "comment": null
},
{
  "id": 4,
  "sample_id": "JS195-C",
  "exposure": "",
  "focus": "30",
  "via_diameter_um": "4",
  "sem_conditions": "",
  "file_name": "landscape.jpg",
  "file_path": "file:///D:/images/",
  "status": null,
  "comment": null
},
{
  "id": 5,
  "sample_id": "JS195-D",
  "exposure": "",
  "focus": "10",
  "via_diameter_um": "3",
  "sem_conditions": "",
  "file_name": "work.jpg",
  "file_path": "file:///D:/images/",
  "status": null,
  "comment": null
},
{
  "id": 1,
  "sample_id": "JS195-A",
  "exposure": "",
  "focus": "10",
  "via_diameter_um": "1",
  "sem_conditions": "",
  "file_name": "mobile_phone.jpg",
  "file_path": "file:///D:/images/",
  "status": "1",
  "comment": "dasdsadada"
}

]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quang H?c Nguy?n