“DataFrame Groupby to Dictionary” Kode Jawaban

DataFrame Groupby to Dictionary

In [81]: df.groupby('Column1')['Column3'].apply(list).to_dict()
Out[81]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}
Fantastic Fish

Konversi kelompok panda menjadi dikte

res = dict(tuple(d.groupby('a')))
Magnificent Moth

DataFrame Groupby to Dictionary

In [433]: {k: list(v) for k, v in df.groupby('Column1')['Column3']}
Out[433]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}
Fantastic Fish

Jawaban yang mirip dengan “DataFrame Groupby to Dictionary”

Pertanyaan yang mirip dengan “DataFrame Groupby to Dictionary”

Lebih banyak jawaban terkait untuk “DataFrame Groupby to Dictionary” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya