How to Get the Maximum Value in a Column of a Pandas DataFrame


Let’s see how we can get the maximum value in a column of a Pandas DataFrame.

Suppose we have a DataFrame df, and we want to obtain the maximum value of the column col.

1. Get row with maximum column value

We have multiple ways to get the entire row that contains the maximum value in a specific column.

df.loc[df['col'].idxmax()]
df[df['col'] == df['col'].max()]
df.iloc[df['col'].argmax()]

We can also use DataFrame.nlargest to get the row with the maximum column value.

df.nlargest(1, 'col')

2. Get just the maximum column value

We can use DataFrame.nlargest to get just the maximum value in a column.

df['col'].nlargest(1)