Closed
Description
Feature Type
-
Adding new functionality to pandas
-
Changing existing functionality in pandas
-
Removing existing functionality in pandas
Problem Description
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_dict.html
Seems like a simple but useful expansion to add a 'jsonlines' output format. I'm not sure it belongs as an 'orient' in the to_dict, but it is very similar to to_dict(orient='records'). The only difference is omitting the surrounding brackets [], and the commas, and using newlines instead of commas to separate each dict record.
Feature Description
# I write out jsonlines like so, given a list of dicts.
import json
list_of_dicts = []
with open('target_file.jsonl', 'w') as f:
for d in list_of_dicts:
f.write(json.dumps(d) + '\n')
Alternative Solutions
Alternative 3rd party package: https://jsonlines.readthedocs.io/en/latest/
(I haven't used it, so I don't know how well it works with edge cases and whatnot)
Additional Context
No response