Skip to content

Instantly share code, notes, and snippets.

@jin-zhe
Created November 24, 2024 11:15
Show Gist options
  • Save jin-zhe/aeacd5a8a0935a4824b0a7315b08ef49 to your computer and use it in GitHub Desktop.
Save jin-zhe/aeacd5a8a0935a4824b0a7315b08ef49 to your computer and use it in GitHub Desktop.
Pandas convenience functions for reading and writing jsonl files.
import pandas as pd
def jsonl_to_df(jsonl_filepath):
return pd.read_json(jsonl_filepath, lines=True)
def df_to_jsonl(df, jsonl_filepath):
payload = df.to_json(orient='records', lines=True)
with open(jsonl_filepath, 'w') as writer:
writer.write(payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment