A DataFrame likes the following.
x y z
0 A a 1
1 A b 2
2 B c 3
3 B d 3
4 B d 4
values_to_dict could return like the following.
{
"A": {
"a": ["1"],
"b": ["2"],
},
"B": {
"c": ["3"],
"d": ["3", "4"],
},
}
The above result is missing columns.
So whether the result should contain columns like the following?
{
[
{
"column": "x",
"value": "A",
"next": [
{
"column": "y",
"value": "a",
"next": {"column": "1", "value": "z"},
},
{
"column": "y",
"value": "b",
"next": {"column": "2", "value": "z"},
},
],
},
{
"column": "x",
"value": "B",
"next": [
{
"column": "y",
"value": "c",
"next": {"column": "3", "value": "z"},
},
{
"column": "y",
"value": "d",
"next": [
{"column": "3", "value": "z"},
{"column": "4", "value": "z"},
],
},
],
},
]
}
A DataFrame likes the following.
values_to_dictcould return like the following.{ "A": { "a": ["1"], "b": ["2"], }, "B": { "c": ["3"], "d": ["3", "4"], }, }The above result is missing columns.
So whether the result should contain columns like the following?
{ [ { "column": "x", "value": "A", "next": [ { "column": "y", "value": "a", "next": {"column": "1", "value": "z"}, }, { "column": "y", "value": "b", "next": {"column": "2", "value": "z"}, }, ], }, { "column": "x", "value": "B", "next": [ { "column": "y", "value": "c", "next": {"column": "3", "value": "z"}, }, { "column": "y", "value": "d", "next": [ {"column": "3", "value": "z"}, {"column": "4", "value": "z"}, ], }, ], }, ] }