Skip to content
Advertisement

How to convert csv to complex json

enter image description here

How to do this stuff in python pandas? I am trying to make put request to some API and not sure how to generate request body since I have the csv file only . Request body asks for fixed set of schema

Advertisement

Answer

Dataframe has a function to_dict.

documents = df.to_dict(orient='records')
result = {'items': documents}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement