From b843115fc2580526e8e717cf2fee8ea47cb0fcf1 Mon Sep 17 00:00:00 2001 From: javad Date: Tue, 8 Nov 2022 11:37:12 +0330 Subject: [PATCH] Change: fix extra line between rows after exporting to csv Change: add jupyter notebook command to run the script --- README.md | 7 +++++++ json_to_csv.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a265be5..b83ab76 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,13 @@ Usage python /path/to/json_to_csv.py node json_in_file_path csv_out_file_path ``` + +If you want to run the script via a jupyter notebook, you can use code below: + +``` +!python "json_to_csv.py" "STATION" "metadata.json" "metadata__2.csv" +``` + Source Specification -------------------- The script expects the json to be given via a file containing diff --git a/json_to_csv.py b/json_to_csv.py index dbbf2f9..0d74480 100644 --- a/json_to_csv.py +++ b/json_to_csv.py @@ -90,7 +90,7 @@ def reduce_item(key, value): header = list(set(header)) header.sort() - with open(csv_file_path, 'w+') as f: + with open(csv_file_path, 'w+', newline='') as f: writer = csv.DictWriter(f, header, quoting=csv.QUOTE_ALL) writer.writeheader() for row in processed_data: