Reputation:
Why does the following error out? What does the notation
s1.iloc[:,0].min()
stand for?
import pandas as pd
import numpy as np
s1 = pd.Series(np.random.rand(5), index=list(range(0, 10, 2)))
s1.iloc[:,0].min()
Traceback (most recent call last):
File "<ipython-input-324-b57fa06dca84>", line 1, in <module>
s1.iloc[:,0].min()
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py", line 1325, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py", line 1662, in _getitem_tuple
self._has_valid_tuple(tup)
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py", line 188, in _has_valid_tuple
raise IndexingError('Too many indexers')
IndexingError: Too many indexers
Upvotes: 3
Views: 393
Reputation: 164623
A series (pd.Series
) object is one-dimensional. It consists of an array-like container of items together with an index.
Therefore, like any one-dimensional array, only one index is permitted.
For the minimum value of a series, use s1.min()
.
The syntax x.iloc[:, 0].min()
is used where x
is a dataframe (pd.DataFrame
). In other words, it is used to calculate the minimum of the first column across all rows.
Upvotes: 2