AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Python json csv10/6/2023 ![]() How should we convert to json if i get different patterns of csv log messages. ![]() but my requirement is i need to convert csv (any pattern) to json.įor the above csv logs i converted like below json. So far i created script to convert one type of csv pattern(above showed) to json. It's just a representation character.I have a scenario, I am receiving logs in csv format to kinesis firehose directly and with help of lambda function (python) I need to transform the csv logs format to json format and return the output back to kinesis. Note that the u prefix that was worrying you doesn't appear in the result. T11:18:41.014792508Z,arduino_1,living_room,32,336,32.96 import json import pandas as pd from pandas.io.json import jsonnormalize from cs import CloudStack apikey xxxx secret xxxx endpoint xxxx cs CloudStack (endpointendpoint, keyapikey, secretsecret) virtualmachines cs.virtMach () test jsonnormalize (virtualmachines 'virtualmachine') test.tocsv ('test.csv', sep'', ind. Output: time,SOURCE,PLACE,TEMP,LIGHT,HUMIDITY Write the header to get the title, then use writerows on the list of dictionaries to write the data. Title = "time,SOURCE,PLACE,TEMP,LIGHT,HUMIDITY".split(",") # quick hackĬw = csv.DictWriter(f,title,delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)įixing title order is done by reusing the order you provided (else order is the dictionary order, not the one you want). With open("output.csv","w",newline="") as f: # python 2: open("output.csv","wb") I have a list of JSON that I print it like this: for item in points:
0 Comments
Read More
Leave a Reply. |