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]
?
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(:).
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) ....
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With