Skip to content
Advertisement

Import text file into csv file

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

Advertisement

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement