From d8f56d0d1c5bf2b001ac6f6ef4d7b29420de4fa1 Mon Sep 17 00:00:00 2001 From: Sarvesh Kumar Dwivedi Date: Sun, 2 Oct 2022 08:22:56 +0000 Subject: [PATCH 1/3] add csv to json script --- scripts/CSV_to_Excel/README.md | 7 +++---- scripts/csv_to_json/README.md | 9 +++++++++ scripts/csv_to_json/script.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 scripts/csv_to_json/README.md create mode 100644 scripts/csv_to_json/script.py diff --git a/scripts/CSV_to_Excel/README.md b/scripts/CSV_to_Excel/README.md index cf48e19..c3afdb6 100644 --- a/scripts/CSV_to_Excel/README.md +++ b/scripts/CSV_to_Excel/README.md @@ -1,9 +1,8 @@ # CSV to EXCEL -This is a simple script that lets you convert CSV files to Excel. +This simple script will convert CSV file to Json. ## Usage -* 2 packages required pandas and openpyxl -* Use `pip install pandas` and `pip install openpyxl` -* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx` +* required pandas package +* Use `pip install pandas` * Run `python script.py` diff --git a/scripts/csv_to_json/README.md b/scripts/csv_to_json/README.md new file mode 100644 index 0000000..cf48e19 --- /dev/null +++ b/scripts/csv_to_json/README.md @@ -0,0 +1,9 @@ +# CSV to EXCEL +This is a simple script that lets you convert CSV files to Excel. + +## Usage + +* 2 packages required pandas and openpyxl +* Use `pip install pandas` and `pip install openpyxl` +* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx` +* Run `python script.py` diff --git a/scripts/csv_to_json/script.py b/scripts/csv_to_json/script.py new file mode 100644 index 0000000..6932150 --- /dev/null +++ b/scripts/csv_to_json/script.py @@ -0,0 +1,16 @@ +import pandas as pd +import os,json + +def csv_to_json(): + file = input("Enter csv path: ") + df = pd.read_csv(file) + name = os.path.basename(file).replace("csv", "json") + data = df.to_dict("r") + with open(name, "w") as file: + json.dump(data,file) + + print(f"file saved at {name}") + + + +csv_to_json() \ No newline at end of file From d231afd19d61339c1297d81f6753a8ef5918760c Mon Sep 17 00:00:00 2001 From: Sarvesh Kumar Dwivedi Date: Sun, 2 Oct 2022 08:28:15 +0000 Subject: [PATCH 2/3] Revert "add csv to json script" This reverts commit d8f56d0d1c5bf2b001ac6f6ef4d7b29420de4fa1. --- scripts/CSV_to_Excel/README.md | 7 ++++--- scripts/csv_to_json/README.md | 9 --------- scripts/csv_to_json/script.py | 16 ---------------- 3 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 scripts/csv_to_json/README.md delete mode 100644 scripts/csv_to_json/script.py diff --git a/scripts/CSV_to_Excel/README.md b/scripts/CSV_to_Excel/README.md index c3afdb6..cf48e19 100644 --- a/scripts/CSV_to_Excel/README.md +++ b/scripts/CSV_to_Excel/README.md @@ -1,8 +1,9 @@ # CSV to EXCEL -This simple script will convert CSV file to Json. +This is a simple script that lets you convert CSV files to Excel. ## Usage -* required pandas package -* Use `pip install pandas` +* 2 packages required pandas and openpyxl +* Use `pip install pandas` and `pip install openpyxl` +* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx` * Run `python script.py` diff --git a/scripts/csv_to_json/README.md b/scripts/csv_to_json/README.md deleted file mode 100644 index cf48e19..0000000 --- a/scripts/csv_to_json/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# CSV to EXCEL -This is a simple script that lets you convert CSV files to Excel. - -## Usage - -* 2 packages required pandas and openpyxl -* Use `pip install pandas` and `pip install openpyxl` -* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx` -* Run `python script.py` diff --git a/scripts/csv_to_json/script.py b/scripts/csv_to_json/script.py deleted file mode 100644 index 6932150..0000000 --- a/scripts/csv_to_json/script.py +++ /dev/null @@ -1,16 +0,0 @@ -import pandas as pd -import os,json - -def csv_to_json(): - file = input("Enter csv path: ") - df = pd.read_csv(file) - name = os.path.basename(file).replace("csv", "json") - data = df.to_dict("r") - with open(name, "w") as file: - json.dump(data,file) - - print(f"file saved at {name}") - - - -csv_to_json() \ No newline at end of file From b9b97c8c4aa2f3b9487c809da73fb41e4508c691 Mon Sep 17 00:00:00 2001 From: Sarvesh Kumar Dwivedi Date: Sun, 2 Oct 2022 08:32:52 +0000 Subject: [PATCH 3/3] add csv to json script --- scripts/csv_to_json/README.md | 8 ++++++++ scripts/csv_to_json/script.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 scripts/csv_to_json/README.md create mode 100644 scripts/csv_to_json/script.py diff --git a/scripts/csv_to_json/README.md b/scripts/csv_to_json/README.md new file mode 100644 index 0000000..5f2d167 --- /dev/null +++ b/scripts/csv_to_json/README.md @@ -0,0 +1,8 @@ +# CSV to EXCEL +This simple script will convert CSV file to json. + +## Usage + +* requires pandas +* Use `pip install pandas` +* Run `python script.py` diff --git a/scripts/csv_to_json/script.py b/scripts/csv_to_json/script.py new file mode 100644 index 0000000..7f8e6b0 --- /dev/null +++ b/scripts/csv_to_json/script.py @@ -0,0 +1,15 @@ +import pandas as pd +import os,json + +def csv_to_json(): + file = input("Enter csv path: ") + df = pd.read_csv(file) + name=os.path.basename(file).replace("csv","json") + data =df.to_dict("r") + with open(file,'w') as f: + json.dump(df, d) + + print(f"file saved at {name}") + + +csv_to_json() \ No newline at end of file