Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions csv_to_json/README.md
Original file line number Diff line number Diff line change
@@ -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 <FILENAME.csv>` // Replace the FILENAME with your csv filename

example: `python main.py Book.csv`
15 changes: 15 additions & 0 deletions csv_to_json/main.py
Original file line number Diff line number Diff line change
@@ -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"
data = pd.read_csv(args[-1]) # load CSV data as Pd object
data.to_json(args[-1][:-4] + ".json", orient='records')
del data
1 change: 1 addition & 0 deletions csv_to_json/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pandas==1.3.3