From 6a9e580d48d14bcffc6c8801beee1d515a3c4382 Mon Sep 17 00:00:00 2001 From: durgeshahire07 Date: Sat, 9 Oct 2021 05:32:05 +0530 Subject: [PATCH 1/3] csv_to_json added --- csv_to_json/README.md | 14 ++++++++++++++ csv_to_json/main.py | 15 +++++++++++++++ csv_to_json/requirements.txt | 1 + 3 files changed, 30 insertions(+) create mode 100644 csv_to_json/README.md create mode 100644 csv_to_json/main.py create mode 100644 csv_to_json/requirements.txt diff --git a/csv_to_json/README.md b/csv_to_json/README.md new file mode 100644 index 000000000..9c2828ccc --- /dev/null +++ b/csv_to_json/README.md @@ -0,0 +1,14 @@ +# Script to convert CSV -> JSON + +Script expect the user to pass CSV file and saves the JSON file at same dir + +## install requirements/dependencies: + +python -r requirements.txt + +## how to use: + +call the program using: +`python main.py //Replace the FILENAME with your csv filename` + +example: `python main.py Book.csv` \ No newline at end of file diff --git a/csv_to_json/main.py b/csv_to_json/main.py new file mode 100644 index 000000000..76ab72f51 --- /dev/null +++ b/csv_to_json/main.py @@ -0,0 +1,15 @@ +import pandas as pd +import sys +import os + +args = sys.argv[1:] # get command line *args +assert args, "No file was provided; Provide a CSV filename" + + +isdir = os.path.isdir(args[-1]) +# If input is CSV file +if not isdir: + assert args[-1].endswith(".csv"), "Input file is not CSV; Provide CSV filename with .csv extension" + data = pd.read_csv(args[-1]) # load CSV data as Pd object + data.to_json(args[-1][:-4] + ".json", orient='records') + del data \ No newline at end of file diff --git a/csv_to_json/requirements.txt b/csv_to_json/requirements.txt new file mode 100644 index 000000000..5c6ce4d33 --- /dev/null +++ b/csv_to_json/requirements.txt @@ -0,0 +1 @@ +pandas==1.3.3 From a5b1e38524afe125dc7a24b8046a0cc414567a94 Mon Sep 17 00:00:00 2001 From: durgeshahire07 Date: Sat, 9 Oct 2021 05:36:17 +0530 Subject: [PATCH 2/3] readme.md updated --- csv_to_json/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csv_to_json/README.md b/csv_to_json/README.md index 9c2828ccc..d2ddd3d98 100644 --- a/csv_to_json/README.md +++ b/csv_to_json/README.md @@ -9,6 +9,6 @@ python -r requirements.txt ## how to use: call the program using: -`python main.py //Replace the FILENAME with your csv filename` +`python main.py ` // Replace the FILENAME with your csv filename example: `python main.py Book.csv` \ No newline at end of file From 9bc6f0695882cb9e37a2cd59b86f270dc36dbf7c Mon Sep 17 00:00:00 2001 From: durgeshahire07 Date: Sat, 9 Oct 2021 05:49:44 +0530 Subject: [PATCH 3/3] resolved flake8linter error --- csv_to_json/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csv_to_json/main.py b/csv_to_json/main.py index 76ab72f51..e619b84f7 100644 --- a/csv_to_json/main.py +++ b/csv_to_json/main.py @@ -9,7 +9,7 @@ isdir = os.path.isdir(args[-1]) # If input is CSV file if not isdir: - assert args[-1].endswith(".csv"), "Input file is not CSV; Provide CSV filename with .csv extension" + assert args[-1].endswith(".csv"), "Input file is not CSV" data = pd.read_csv(args[-1]) # load CSV data as Pd object - data.to_json(args[-1][:-4] + ".json", orient='records') - del data \ No newline at end of file + data.to_json(args[-1][:-4] + ".json", orient='records') + del data