I have a series object (1 column of a DataFrame) and would like to extract the value of the first element. Is there a way to do this simply without converting to a list and without knowing the key? Or is the only way to access it by converting it to a list first using tolist()[n]?
Asked
Active
Viewed 1.6k times
6
Moppentapper
- 289
- 2
- 4
- 10
1 Answers
15
I think you can use iloc:
print df
col
0 a
1 b
2 c
3 d
4 e
print df.iloc[0]
col a
Name: 0, dtype: object
jezrael
- 729,927
- 78
- 1,141
- 1,090
-
Thanks! When I was looking around the web I found the `iloc()` function, which returns an indexer, but not the value. Using `iloc[n]` with the square brackets works. No need for the `.values`. – Moppentapper Apr 19 '16 at 07:02