Get the maximum value of column in pandas python : In this tutorial we will learn How to get the maximum value of all the columns in dataframe of python pandas. How to get the maximum value of a specific column or a series by using max() function.
Syntax of Pandas Max() Function:
axis | 0 – Rows wise operation |
1- Columns wise operation | |
skipna | Exclude NA/null values when computing the result |
If the axis is a Multi index (hierarchical), count along a particular level, collapsing into a Series | |
numeric_only | Include only float, int, boolean columns. If None, will attempt to use everything |
We will looking at an example on
- How to get Column wise maximum value of all the column.
- Get Maximum value of a specific column by name
- Get Maximum value of series in pandas python
- Get Maximum value of a specific column by index
Create Dataframe:
import pandas as pd import numpy as np #Create a DataFrame d = { 'Name':['Alisa','Bobby','jodha','jack','raghu','Cathrine', 'Alisa','Bobby','kumar','Alisa','Alex','Cathrine'], 'Age':[26,24,23,22,23,24,26,24,22,23,24,24], 'Score':[85,63,55,74,31,77,85,63,42,62,89,77]} df = pd.DataFrame(d,columns=['Name','Age','Score']) df
So the resultant dataframe will be
Get the maximum value of all the column in python pandas:
# get the maximum values of all the column in dataframe df.max()
This gives the list of all the column names and its maximum value, so the output will be
Get the maximum value of a specific column in pandas:
Example 1:
# get the maximum value of the column 'Age' df['Age'].max()
This gives the maximum value of column “Age” so the output will be
26
Example 2:
# get the maximum value of the column 'Name' df['Name'].max()
This gives the maximum value of column “Name” so the output will be
Get the maximum value of a specific column in pandas by column index:
# get the maximum value of the column by column index df.iloc[:, [1]].max()
df.iloc[] gets the column index as input here column index 1 is passed which is 2nd column (“Age” column), maximum value of the 2nd column is calculated using max() function as shown.
Get Maximum value of the series in pandas :
Lastly we would see how to calculate the maximum value of a series in pandas by using max() function . First lets create a series of alphabets as shown below
### Create a series import pandas as pd import numpy as np data = np.array(['a','b','c','d','e','f']) ser = pd.Series(data,index=[1000,1001,1002,1003,1004,1005])
created series is
Maximum value of a series is calculated using series.max() function as shown below
### Calculate maximum value of a series ser.max()
so the resultant max value of the series is