Let's say I have the following df
:
0 0 1 1 2 2 3 3 4 4 5 5
0 Fondo Oceano Cuerpo Cuerpo cangrejo Ojos Antenas Color Amarillo Pinzas None Puas None
1 Fondo Oceano Cuerpo Cuerpo cangrejo Ojos Antenas Color Amarillo Pinzas None Puas Arena
2 Fondo Oceano Cuerpo Cuerpo cangrejo Ojos Antenas Color Amarillo Pinzas None Puas Marron
3 Fondo Oceano Cuerpo Cuerpo cangrejo Ojos Antenas Color Amarillo Pinzas None Puas Purpura
4 Fondo Oceano Cuerpo Cuerpo cangrejo Ojos Antenas Color Amarillo Pinzas None Puas Verde
I know I can use Series.iteritems
this way to iterate over a particular row in this df
and print the content of each cell in a particular row (ignoring the index column):
row = 0 #desired row
for _, e in df.iloc[row].iteritems():
print(e)
Output:
Fondo
Oceano
Cuerpo
Cuerpo cangrejo
Ojos
Antenas
Color
Amarillo
Pinzas
None
Puas
None
But what I need like to learn now is how could I improve the loop above so that it creates a dictionary that has even cells as keys
and odd cells as values
respectively?
In other words, how could I get the following dictionary for the 0
row as output?
the_dic = { 'Fondo':'Oceano',
'Cuerpo': 'Cuerpo cangrejo',
'Ojos': 'Antenas',
'Color': 'Amarillo',
'Pinzas': 'None',
'Puas': 'None'
}
PS: The 'None' element in this case is a str
value and not the object None