LoginSignup
44
21

More than 1 year has passed since last update.

pandasでjsonlを扱いたい時

Last updated at Posted at 2017-10-31

jsonlとは

jsonlとは、1レコードがjsonになっているファイルです。

フォーマットの例

 {"title": "學問のすゝめ", "author": "福澤諭吉", "content": "天は人の上に人を造らず人の下に人を造らずと云へり。"}
 {"title": "人間失格", "author": "太宰治", "content": "私は、その男の写真を三葉、見たことがある。"}
 {"title": "銀河鉄道の夜", "author": "宮沢賢治", "content":"ではみなさんは、そういうふうに川だと言われたり、乳の流れたあとだと言われたりしていた、このぼんやりと白いものがほんとうは何かご承知ですか"}

jsonlでの読み込み方法

pandasを使用して、jsonlを読み込みたい時は以下のようにします。

df = pd.read_json('hogehoge.jsonl', orient='records', lines=True)

jsonlでの出力方法

DataFrameから、jsonlで出力する時は、以下のようにします。

df.to_json('hogehoge.jsonl', orient='records', force_ascii=False, lines=True)
44
21
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
44
21