Skip to content

Instantly share code, notes, and snippets.

@MicPie
Created October 9, 2022 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MicPie/366538eb11787ab51f48b7a8be2564f5 to your computer and use it in GitHub Desktop.
Save MicPie/366538eb11787ab51f48b7a8be2564f5 to your computer and use it in GitHub Desktop.
ISP csv to jsonl script
import argparse
import pandas as pd
import json
def main():
parser = argparse.ArgumentParser(description="List the content of a folder")
parser.add_argument(
"path",
metavar="path",
type=str,
help="path to the input csv",
)
args = parser.parse_args()
path_csv = args.path
print(f"CSV file used for the expor: {path_csv}")
path_jsonl = path_csv.replace(".csv", ".jsonl")
df = pd.read_csv(path_csv)
df.classes = df.classes.apply(lambda x: json.loads(x.replace("'","\""))) # create list from string list
with open(path_jsonl, "w") as f:
f.write(df.to_json(orient="records", lines=True))
print(f"CSV file exported to: {path_jsonl}")
if __name__ == "__main__":
main()
@MicPie
Copy link
Author

MicPie commented Oct 9, 2022

Run with python csv2jsonl.py yourdata.csv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment