You can see the name of parent is color start with child_id 0 and children is red and blue that binds id from color.
I like to get the data in the table to make it into Json how to do?
My data
import pandas as pd
data = {
'id': ['2', '13', '14', '15'],
'name': ['color', 'red', 'blue', 'ruby red'],
'child_id': ['0', '2', '2', '13']
}
df = pd.DataFrame(data)
df
Expected Output
[
{
"name": "color",
"id": 2,
"child_id": 0,
"children": [
{
"name": "red",
"id": 13,
"child_id": 2,
"children": [
{
"name": "ruby red",
"id": 15,
"child_id": 13,
}
]
},
{
"name": "blue",
"id": 14,
"child_id": 2
}
]
}
]
