I am having the issue in converting the row-wise data of dataframe with the column name as key and row data as value. I want to pass this row-wise json to another API as an input. I am unable to get this json data.
for row in df.iterrows():
out =row.to_json(orient='records',force_ascii=False)[1:-1].replace('},{', '} {')
r = requests.post(url, headers=headers, data=out.encode('utf-8'))
print(r.json())
I want the desired output of the json in the attached format
解决方案
Try this:
import requests
import pandas as pd
def call_api(json_data):
r = requests.post(url, headers=headers, data=out)
print(r.json())
df.apply(lambda x:call_api(x.to_json()),axis=1)
Hope this helps!