I would like to get for each category/eye colour to have all the associated first names.
Here is my dataframe (df):
eye color first name
0 blue Jules
1 blue Lucie
2 green Thomas
3 green Vincent
4 green David
5 brown Maxime
This is the output I would like to have:
{'blue': ['Jules', 'Lucie'], 'green': ['Thomas', 'Vincent', 'David'], 'brown': ['Maxime']
This is my code:
list_name=list()
for i in range(len(df)-1):
current_color=df['eye color'][i]
next_color=df['eye color'][i+1]
name=df['first name'][i]
if current_color!=next_color :
compte_nb_systeme=compte_nb_systeme+1
print('we change eye color')
else :
print('we don't change the color of the eye')
list_name.append(name)
dico= {current_color :list_name}
print(dico)
the problem is that I add all the names contained in the column 'first name' and that for each color of eyes.