Jun-02-2021, 02:52 PM
Greetings,
I am trying to write a Pandas DataFrame to a json file.
The json file gets overwritten, rather than appended??
Can anyone spot the error??
Any pointers appreciated.
The pprint statement returns 1 row with 4 columns .... hundreds of!!
I only get a single json element??
The code snippet:
I am trying to write a Pandas DataFrame to a json file.
The json file gets overwritten, rather than appended??
Can anyone spot the error??
Any pointers appreciated.
The pprint statement returns 1 row with 4 columns .... hundreds of!!
I only get a single json element??
The code snippet:
with open(outFile, 'w', newline='') as jsonfile: #filewriter = json.writer(jsonfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) #filewriter.writerow(['reportname', 'report-data', 'report', 'time-slices']) for service in srv.services.list(): if service.properties.serviceName != " ": #print(service) #time_slices = 'time-slices' for report in service: query_string = "17224-0.0*" qk_report = srv.usage.quick_report(since="LAST_MONTH", queries=query_string, metrics="report") flat = pd.json_normalize(qk_report) #### use pd.json_normalize #pprint(flat) df = DataFrame(flat, columns=['report.reportname', 'report.report-data', 'report.report', 'report.time-slices']) pprint(df) df.to_json(outFile, orient='table')