24000
1800014000
我正在csv文件上工作。csv表文件结构如下
如果我没理解错的话,你是想按"品牌"进行分组。然后创建一个字典:
out = {}
for b, g in df.groupby("brands"):
out[b] = {
row["models"]: {
"2020": row["2020_price"],
"2021": row["2021_price"],
}
for _, row in g.iterrows()
}
print(out)
打印:
{
"chevrolet": {
"Traverse": {"2020": 24000, "2021": 320000},
"Equinox": {"2020": 18000, "2021": 23000},
"Trailblazer": {"2020": 14000, "2021": 13000},
}
}