Sep-01-2022, 06:00 AM
(This post was last modified: Sep-01-2022, 06:13 AM by deanhystad.)
You are using a writer to write dictionaries. You should be using a DictWriter. The writer is iterating through your dictionaries to write the rows, and when you iterate through a dictionary you get the keys, not the values.
Using the link provided in you post I wrote this:
Using the link provided in you post I wrote this:
import json import csv import pandas as pd response = """{ "totalRecords": 992, "maxPageSize": 100, "currentPageSize": 1, "nextPageLink": null, "nextCursor": 12935, "data": [ { "id": 12729, "checklistName": "Signature", "description": "Signature", "user": "Wagner Robin", "userId": 3196, "checklistDate": "03-01-2020", "accountCode": "DM24" } ] }""" response = json.loads(response) data = [response["data"]] with open('data.csv','w',encoding='UTF8', newline='')as f: writer = csv.DictWriter(f, data[0][0].keys()) writer.writeheader() for page in data: writer.writerows(page) df = pd.read_csv("data.csv") print(df)Which produces this output:
Output: id checklistName description user userId checklistDate accountCode
0 12729 Signature Signature Wagner Robin 3196 03-01-2020 DM24