Created
October 9, 2022 18:22
-
-
Save MicPie/366538eb11787ab51f48b7a8be2564f5 to your computer and use it in GitHub Desktop.
ISP csv to jsonl script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with
python csv2jsonl.py yourdata.csv
.