I currently have my file loaded as follows:
import ndjson
with open('full_simplified_arm.ndjson') as f:
data = ndjson.load(f)
However, I would like to convert this file into a csv in Python and was wondering how to do this? Thanks
I currently have my file loaded as follows:
import ndjson
with open('full_simplified_arm.ndjson') as f:
data = ndjson.load(f)
However, I would like to convert this file into a csv in Python and was wondering how to do this? Thanks
You could do it with
csv.DictWriter
.Loading the data with
ndjson.load
, it is stored in this form.You could take the keys from the first item in the list as the fieldnames of the table.
Then define a
csv.DictWriter
to write the header and the rows.Complete solution:
Input
Output
Note: The sample data was retrieved online