To find the maximum value of a column in pandas, the easiest way is to use the pandas max() function.

df["Column"].max()

You can also use the numpy max() function.

np.max(df["Column"])

Finding the maximum value of numbers in a column, or the maximum value of all numbers in a DataFrame using pandas is easy. We can use the pandas max() function to find the maximum values in a column of numbers, or a DataFrame.

Let’s say we have the following DataFrame.

df = pd.DataFrame({'Name': ['Jim', 'Sally', 'Bob', 'Sue', 'Jill', 'Larry'],
                   'Weight': [160.20, 123.81, 209.45, 150.35, 102.43, 187.52]})

print(df)
# Output: 
    Name  Weight
0    Jim  160.20
1  Sally  123.81
2    Bob  209.45
3    Sue  150.35
4   Jill  102.43
5  Larry  187.52

To get the maximum value of the numbers in the column “Weight”, we can use the pandas max() function in the following Python code:

print(df["Weight"].max())

# Output:
209.45

Please note, you can use the pandas max() function on an entire DataFrame if the DataFrame only contains numbers. If we call it on the DataFrame from above, we will receive an error because the “Name” column is made up of strings.

Using numpy max to Calculate Maximum Value in pandas DataFrame

We can also use the numpy max() function to calculate the maximum value of the numbers in a column in a pandas DataFrame.

To get the maximum value of the numbers in the column “Weight”, we can use the numpy max() function in the following Python code:

print(np.max(df["Weight"]))

# Output:
209.45

As you can see above, this is the same value we received from the pandas min() function.

If you are looking to find the maximum value of a set of numbers in regular Python, you can use the python max() function.

If on the other hand you are looking to find the minimum value of a set of numbers, you can use the pandas min() function.

Hopefully this article has been helpful for you to understand how to find the maximum value of numbers in a Series or DataFrame in pandas.

Categorized in:

Python,

Last Update: February 26, 2024