• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

pandas explode

date: 2023-03-13 excerpt: pandasのexplodeの使い方

tag: pythonpandasexplodeexpand


pandasのexplodeの使い方

概要

  • 収められている値がlistのとき、listを展開して新たなデータフレームを作る操作

具体例

import pandas as pd
df = pd.DataFrame()
df["a"] = [[1,2,3], [4, 5,6]]
df
index a
0 1,2,3
1 4,5,6
df.explode("a")
index a
0 1
0 2
0 3
1 4
1 5
1 6

Google Colab

  • pandas-explode-example

参考

  • pandas.DataFrame.explode/pandas.pydata.org


pythonpandasexplodeexpand Share Tweet