Created
November 24, 2024 11:15
-
-
Save jin-zhe/aeacd5a8a0935a4824b0a7315b08ef49 to your computer and use it in GitHub Desktop.
Pandas convenience functions for reading and writing jsonl files.
This file contains hidden or 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 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