Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: adding jsonline output format #58123

Closed
1 of 3 tasks
nathanneuro opened this issue Apr 2, 2024 · 3 comments
Closed
1 of 3 tasks

ENH: adding jsonline output format #58123

nathanneuro opened this issue Apr 2, 2024 · 3 comments
Assignees

Comments

@nathanneuro
Copy link

nathanneuro commented Apr 2, 2024

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

@nathanneuro nathanneuro added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 2, 2024
@Aloqeely
Copy link
Contributor

Aloqeely commented Apr 2, 2024

Maybe DataFrame.to_json() is what you're looking for?
You can pass lines=True and orient='records' to get your desired output

@yukitakah
Copy link

take

@WillAyd
Copy link
Member

WillAyd commented Apr 28, 2024

Agreed with @Aloqeely

@WillAyd WillAyd closed this as completed Apr 28, 2024
@WillAyd WillAyd added Usage Question and removed Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants