So, here I did got my answer but instead of printing it once, It is printing 7 times. Output userID,Is salary credited before 5th,Avg Salary of last 3 months,Avg Salary of last 6 months,Avg Balance before salary of last 3 months,Avg Balance before salary of last 6 monthsĦ79d3bad-155e-4b39-9ff7-7d564f408942,Yes,15453.33,15290.5,113.15,105.22 And, the default value of sort_keys is False.Following is my json file input Ĭode with open('/Users/vrindabv/Documents/PycharmProjects/BankStatementEngine/test.json', "r") as f:į = csv.writer(open("/Users/vrindabv/Documents/PycharmProjects/BankStatementEngine/test.csv", "w"))į.writerow()į.writerow(, x, And, the keys are sorted in ascending order.īy the way, the default value of indent is None. import json import csv f open ('data.json') data json.load (f) f.close () f open ('data.csv') csvfile csv.writer (f) for item in data: csvfile.writerow (item) f.close () However, it did not work. In the above program, we have used 4 spaces for indentation. Once you have done that, you can do the following using Pandas to write the CSV file: import pandas as pd df pd.readjson (r) df.tocsv ('output.csv') Share Improve this answer Follow edited at 8:54 answered at 13:18 n1k31t4 14.4k 2 26 47 well that is perfect answer. When you run the program, the output will be: Print(json.dumps(person_dict, indent = 4, sort_keys=True)) It's common to transmit and receive data between a server and web application in JSON format. JSON ( Java Script Object Notation) is a popular data format used for representing structured data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |