In [1]:
import pandas as pd

In [2]:
df = pd.DataFrame({'col1': [0, 3, 2, 3], 'col2': [4, 0, 2, 1]},
                   index=['a', 'b', 'c', 'd'])

In [3]:
print(df)


   col1  col2
a     0     4
b     3     0
c     2     2
d     3     1

In [4]:
print(df['col1'])


a    0
b    3
c    2
d    3
Name: col1, dtype: int64

In [5]:
print(type(df['col1']))


<class 'pandas.core.series.Series'>

In [6]:
print(df['col1'].max())


3

In [7]:
print(df['col1'].min())


0

In [8]:
print(df.max())


col1    3
col2    4
dtype: int64

In [9]:
print(df.min())


col1    0
col2    0
dtype: int64

In [10]:
print(df.max(axis=1))


a    4
b    3
c    2
d    3
dtype: int64

In [11]:
print(df.min(axis=1))


a    0
b    0
c    2
d    1
dtype: int64

In [12]:
print(type(df.max()))


<class 'pandas.core.series.Series'>

In [13]:
print(df['col1'].idxmax())


b

In [14]:
print(df['col1'].idxmin())


a

In [15]:
print(df['col1'] == df['col1'].max())


a    False
b     True
c    False
d     True
Name: col1, dtype: bool

In [16]:
print(df['col1'][df['col1'] == df['col1'].max()])


b    3
d    3
Name: col1, dtype: int64

In [17]:
print(df['col1'][df['col1'] == df['col1'].max()].index)


Index(['b', 'd'], dtype='object')

In [18]:
print(df['col1'][df['col1'] == df['col1'].max()].index.values)


['b' 'd']

In [19]:
print(type(df['col1'][df['col1'] == df['col1'].max()].index.values))


<class 'numpy.ndarray'>

In [20]:
print(list(df['col1'][df['col1'] == df['col1'].max()].index))


['b', 'd']

In [21]:
print(type(list(df['col1'][df['col1'] == df['col1'].max()].index)))


<class 'list'>

In [22]:
print(df['col1'][df['col1'] == df['col1'].min()].index.values)


['a']

In [23]:
print(df.loc['a'])


col1    0
col2    4
Name: a, dtype: int64

In [24]:
print(df.loc['a'].idxmax())


col2

In [25]:
print(df.loc['a'].idxmin())


col1

In [26]:
print(df.idxmax())


col1    b
col2    a
dtype: object

In [27]:
print(df.idxmin())


col1    a
col2    b
dtype: object

In [28]:
print(df.apply(lambda x: list(x[x == x.max()].index)))


col1    [b, d]
col2       [a]
dtype: object

In [29]:
print(df.apply(lambda x: list(x[x == x.min()].index)))


col1    [a]
col2    [b]
dtype: object

In [30]:
print(df.idxmax(axis=1))


a    col2
b    col1
c    col1
d    col1
dtype: object

In [31]:
print(df.idxmin(axis=1))


a    col1
b    col2
c    col1
d    col2
dtype: object

In [32]:
print(df.apply(lambda x: list(x[x == x.max()].index), axis=1))


a          [col2]
b          [col1]
c    [col1, col2]
d          [col1]
dtype: object

In [33]:
print(df.apply(lambda x: list(x[x == x.min()].index), axis=1))


a          [col1]
b          [col2]
c    [col1, col2]
d          [col2]
dtype: object

In [34]:
df_nan = df.copy()
df_nan.at['b'] = pd.np.nan

In [35]:
print(df_nan)


   col1  col2
a   0.0   4.0
b   NaN   NaN
c   2.0   2.0
d   3.0   1.0

In [36]:
print(df_nan.idxmax())


col1    d
col2    a
dtype: object

In [37]:
print(df_nan.idxmin())


col1    a
col2    d
dtype: object

In [38]:
print(df_nan.idxmax(axis=1))


a    col2
b     NaN
c    col1
d    col1
dtype: object

In [39]:
print(df_nan.idxmin(axis=1))


a    col1
b     NaN
c    col1
d    col2
dtype: object

In [40]:
print(df_nan.idxmax(skipna=False))


col1   NaN
col2   NaN
dtype: float64

In [41]:
print(df_nan.idxmin(skipna=False))


col1   NaN
col2   NaN
dtype: float64

In [42]:
print(df_nan.idxmax(axis=1, skipna=False))


a    col2
b     NaN
c    col1
d    col1
dtype: object

In [43]:
print(df_nan.idxmin(axis=1, skipna=False))


a    col1
b     NaN
c    col1
d    col2
dtype: object

In [44]:
print(df_nan['col1'].idxmax())


d

In [45]:
print(df_nan['col1'].idxmin())


a

In [46]:
print(df_nan['col1'].idxmax(skipna=False))


nan

In [47]:
print(df_nan['col1'].idxmin(skipna=False))


nan