I have a .csv file which I would like to convert into a .jsonl file.
I found the Pandas to_json method:
df = pd.read_csv('DIRECTORY/texts1.csv', sep=';')
df.to_json ('DIRECTORY/texts1.json')
However, I am not aware of a function to turn it into a .jsonl format. How can I do this?
This is probably a bit late, but I wrote a silly module called csv-jsonl that may help with this sort of thing.
>>> from csv_jsonl import JSONLinesDictWriter
>>> l = [{"foo": "bar", "bat": 1}, {"foo": "bar", "bat": 2}]
>>> with open("foo.jsonl", "w", encoding="utf-8") as _fh:
... writer = JSONLinesDictWriter(_fh)
... writer.writerows(l)
...
It extends the native csv module, so it's mostly familiar. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With