I have 2 dataframes. I have to send these two dataframes in json format whenever the django API is called.
c = a.to_json(orient='records')
d = b.to_json(orient='records')
return JsonResponse(json.loads(c,d),safe = False)
a and b are dataframes
I'm getting error when I'm executing the above code. How to send the 2 separate dataframes in json format.
You need to put the dataframes into some sort of structure that can then be serialized back to json. One way would be:
c = json.loads(a.to_json(orient='records'))
d = json.loads(b.to_json(orient='records'))
return JsonResponse([c, d], safe = False)
This will avoid having a double-serialized string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.