更新时间:2023-02-17 12:54:50
您可以 groupby
,汇总到列表中,返回 rec.array
与 to_records
并根据结果构建字典:
You can groupby
, aggregate to lists, return a rec.array
with to_records
and construct a dictionary from the result:
dict(df.groupby('Model').agg(list).to_records())
# {'Ford': ['F-150', 'Escape', 'Mustang'], 'Jeep': ['Grand Cherokee', 'Wrangler']}