NoahVerner
NoahVerner

Reputation: 867

How to get the last element in a particular row from a df on Python without using column names nor loops? Pandas related

If I have a df like this one down below:

       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    

How can I get the last element from a row like 0 without having to iterate over the row nor using the name of the last columns (5 in this case)?

Expected Output for the row 0:

None

Upvotes: 0

Views: 68

Answers (1)

BoomBoxBoy
BoomBoxBoy

Reputation: 1885

You can do that with the following

df[df.columns[-1]][0]

Upvotes: 1

Related Questions