I have a dataframe like the following:
Keyword Value
0 K1 V1
1 K2 V2
2 K3 V3
And I would like to return a json like so:
{
"K1":"V1",
"K2":"V2",
"K3":"V3"
}
My approach right now is to basically convert to dictionary first with df.to_dict(orient='list')
, extract the Keyword and Value lists, go through the lists and create a separate dictionary, then convert to json. I would like to know if there is a more elegant and direct way to do this from the dataframe itself. Thanks.