У меня есть следующий фреймворк с именами людей и их аббревиатурой. Цель состоит в том, чтобы вызывать неоднозначность имени:
Names Abb
0 Michaele Frendu [Mic, Fre]
1 Lucam Zamit [Luc, Zam]
2 magistro Johanne Luckys [Joh, Luc]
3 Albano Fava [Alb, Fav]
4 Augustino Bagliu [Aug, Bag]
5 Lucas Zamit [Luc, Zam]
6 Jngabellavit [Jng]
7 Micheli Frendu [Mic, Fre]
8 Luce [Luc]
9 Far [Far]
Могу ли я группироваться по списку, например: строка 1, 7 и строка 1,5. Позже я собирался сделать что-то похожее только с именами.
Если хотите list
groupby, необходимо сначала преобразовать столбец в кортежи:
def func(x):
print (x)
#some code
return x
df1 = df.groupby(df['Abb'].apply(tuple)).apply(func)
Names Abb
3 Albano Fava [Alb, Fav]
Names Abb
3 Albano Fava [Alb, Fav]
Names Abb
4 Augustino Bagliu [Aug, Bag]
Names Abb
9 Far [Far]
Names Abb
6 Jngabellavit [Jng]
Names Abb
2 magistro Johanne Luckys [Joh, Luc]
Names Abb
8 Luce [Luc]
Names Abb
1 Lucam Zamit [Luc, Zam]
5 Lucas Zamit [Luc, Zam]
Names Abb
0 Michaele Frendu [Mic, Fre]
7 Micheli Frendu [Mic, Fre]
In the current implementation apply calls func twice on the first group to decide whether it can take a fast or slow code path. This can lead to unexpected behavior if func has side-effects, as they will take effect twice for the first group.
, In the current implementation apply calls func twice on the first group to decide whether it can take a fast or slow code path. This can lead to unexpected behavior if func has side-effects, as they will take effect twice for the first group.
, In the current implementation apply calls func twice on the first group to decide whether it can take a fast or slow code path. This can lead to unexpected behavior if func has side-effects, as they will take effect twice for the first group.
Или map
:
df.groupby(df['Abb'].map(tuple)).do_something
Я делаю это, потому что список не является хэш-объектами