Код: Выделить всё
Region Country AREA_CODE
===================================
AMER US A1
AMER CANADA A1
AMER US B1
AMER US A1
Код: Выделить всё
{
"AMER": {
"US": ["ALL", "A1", "B1"],
"CANADA": ["ALL", "A1"]
}
}
Код: Выделить всё
df.drop_duplicates().groupby(["Region", "Country"]).groupby("Country")['AREA_CODE'].agg(lambda x: ["ALL"]+sorted(x.unique().tolist())).to_dict()
Спасибо,
Подробнее здесь: https://stackoverflow.com/questions/791 ... er-columns
Мобильная версия