Previously I followed the solution from this question , but then I realized that it's not the same with my case, I'd like to display some values for the same as_of_dates
and ID
in the display_rows
section in the JSON file, I have a dataframe like this:
as_of_date create_date ID value_1 count value_3
0 02/03/2021 02/03/2021 12345 5 2 55
1 02/03/2021 01/03/2021 12345 8 2 55
2 02/03/2021 01/03/2021 34567 9 1 66
3 02/03/2021 02/03/2021 78945 9 1 77
4 03/03/2021 02/03/2021 78945 9 1 22
5 03/03/2021 02/03/2021 12345 5 1 33
where count
column is the number of the rows for the same ID
& as_of_date
, for example, for as_of_date=02/03/2021
and ID=12345
,there are two rows (each row has different create_date
but I don't care about the create_date
), so count
for the first two rows are the same: 2.
The expected JSON is:
{
"examples": [
{
"Id": 12345,
"as_of_date": "2021-03-02 00:00:00", # this field is datetime format
"value_3": 55,
"count": 2, # for the same 'ID=12345'&'as_of_date=02/03/2021'
"display_rows": [
{
"value_1": 5,
"type": "int" # 'type' field will always be 'int'
},
{
"value_1": 8,
"type": "int"
}
]
},
{
"Id": 34567,
"as_of_date": "2021-03-02 00:00:00",
"value_3": 66,
"count": 1,
"display_rows": [
{
"value_1": 9,
"type": "int"
}
]
},
{
"Id": 78945,
"as_of_date": "2021-03-02 00:00:00",
"value_3": 77,
"count": 1,
"display_rows": [
{
"value_1": 9,
"type": "int"
}
]
},
{
"Id": 78945,
"as_of_date": "2021-03-03 00:00:00",
"value_3": 22,
"count": 1,
"display_rows": [
{
"value_1": 9,
"type": "int"
}
]
},
{
"Id": 12345,
"as_of_date": "2021-03-03 00:00:00",
"value_3": 33,
"count": 1,
"display_rows": [
{
"value_1": 5,
"type": "int"
}
]
}
]
}
It took me almost a whole day to figure out, but seems not working... Can someone help please? Thanks.