I have dataframe
that has "input" as the index of all of the rows. Thousands of them.
df1 =
index item name item quantity
input apple 4
input orange 3
input lemon 6
I need to turn it to a jsonl
file looking like this. I need it looking like this because of the requirement in Shopify GraphQL Admin API Bulk import.
{ "input": { "item name": "apple", "item quantity": "4"}}
{ "input": { "item name": "orange", "item quantity": "3"}}
{ "input": { "item name": "lemon", "item quantity": "6"}}
I can use df1.to_json(orient='records', lines=True)
to convert it into jsonl
without the index to look like this
{ "item name": "apple", "item quantity": "4"}}
{ "item name": "orange", "item quantity": "3"}}
{ "item name": "lemon", "item quantity": "6"}}
But i will need to add the key "input" to the front which i dont know how to do it. I am new to json.
I also tried df1.to_json(orient="index")
but it gives me an error ValueError: DataFrame index must be unique for orient='index'
indicating that every index must be unique.
Any help is appreciated. Cheers