Import text file into csv file

Tags: , ,



I am new in Python and looking to change text data in csv data, where column contains id, sequence, createdAt, and createdBy?

Text File

[{“id”:1,”sequence”:14,”createdAt”:”2021-03-04xx:x:x”,”createdBy”:”xxxxxxxxxxxx”}},

{“id”:2,”sequence”:14,”createdAt”:”2021-03-04Txx:x:x”,”createdBy”:”xxxxxxxxxxxx”}},

{“id”:3,”sequence”:14,”createdAt”:”2021-03-04Txx:x:x”,”createdBy”:”xxxxxxxxxxxx”}}]

Result

My results looks like

image

Answer

Input Data Set appears to be JSON structure
I’d recommend csvkit https://csvkit.readthedocs.io/en/latest/index.html

Specifically , module in2csv – very powerful

Alternatively – use pandas read_json – this will enable you load into a DataFrame



Source: stackoverflow