Get first element of Series without knowing the index [duplicate] Get first element of Series without knowing the index [duplicate] python python

Get first element of Series without knowing the index [duplicate]


Use iloc to access by position (rather than label):

In [11]: df = pd.DataFrame([[1, 2], [3, 4]], ['a', 'b'], ['A', 'B'])In [12]: dfOut[12]:    A  Ba  1  2b  3  4In [13]: df.iloc[0]  # first row in a DataFrameOut[13]: A    1B    2Name: a, dtype: int64In [14]: df['A'].iloc[0]  # first item in a Series (Column)Out[14]: 1