Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve value of n-th element in pandas Series object?

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]?

like image 249
Moppentapper Avatar asked Apr 19 '16 06:04

Moppentapper


People also ask

How do you get element from pandas series?

Accessing Element from Series with Position Use the index operator [ ] to access an element in a series. The index must be an integer. In order to access multiple elements from a series, we use Slice operation. Slice operation is performed on Series with the use of the colon(:).

How do you find the nth column in pandas?

The following should work: df. ix[:, ::2] - get every second column, beginning with first (here all a's) df. ix[:, 1::2] - get every second column, beginning with second (b's) ....

How do I check pandas series value?

isin() function check whether values are contained in Series. It returns a boolean Series showing whether each element in the Series matches an element in the passed sequence of values exactly.


1 Answers

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
like image 75
jezrael Avatar answered Oct 06 '22 09:10

jezrael