Highlight the maximum value in last two columns in Pandas - Python Last Updated : 26 Jul, 2020 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to highlight the maximum values in Pandas Dataframe. Let's first make a dataframe: Example: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = {'Name': ['Sumit Tyagi', 'Sukritin', 'Akriti Goel', 'Sanskriti', 'Abhishek Jain'], 'Age': [22, 20, np.nan, np.nan, 22], 'Marks': [90, 84, 33, 87, 82]} # Converting Dictionary to Pandas Dataframe df = pd.DataFrame(dict) # Print Dataframe df Output: Now, come to the highlighting part. Our objective is to highlight cells with maximum values in last 2 columns. Method 1: Highlighting Cell with maximum value in last 2 columns We will do this by using the highlight_max() method of DataFrame property. highlight_max() method takes 3 arguments, subset: name of the columns of which you want to find the maximumcolor: name of the color with which you want to highlight the cellaxis: (0/1) based on which axis you want to find the maximum. Example: Python3 # Highlighting the maximum values # of last 2 columns df.style.highlight_max(subset = ['Age', 'Marks'], color = 'lightgreen', axis = 0) Output: Method 2: Instead of using column names we generalise it to last two columns Example: Python3 # Highlighting the maximum values of # last 2 columns df.style.highlight_max(subset = df.columns[-2:], color = 'lightgreen', axis = 0) Output: Method 3: Highlighting the text instead of cellExample: Python3 # Defining custom function which returns # the list for df.style.apply() method def highlight_max(s): is_max = s == s.max() return ['color: green' if cell else '' for cell in is_max] df.style.apply(highlight_max, subset = df.columns[-2:]) Output: Method 4: Highlighting cell with maximum valuesExample: Python3 # Defining custom function which returns # the list for df.style.apply() method def highlight_max(s): is_max = s == s.max() return ['background: lightgreen' if cell else '' for cell in is_max] df.style.apply(highlight_max, subset = df.columns[-2:]) Output: Comment More infoAdvertise with us Next Article Highlight the maximum value in last two columns in Pandas - Python S sumit_tyagi Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame pandas-dataframe-program Practice Tags : python Similar Reads Highlight the maximum value in each column in Pandas Let's discuss how to highlight the maximum values in Pandas Dataframe. Lets first make a dataframe: Example: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = {'Name': ['Sukritin', 'Sumit Tyagi', 'Akriti Goel', 'Sanskriti', 'Abh 2 min read Highlight the minimum value in each column In Pandas In this article, we will discuss how to Highlight the minimum values in Pandas Dataframe. So, Let's first make a dataframe: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = { 'Name': ['Sumit Tyagi', 'Sukritin', 'Akriti Goel', ' 3 min read How to Get the maximum value from the Pandas dataframe in Python? Python Pandas max() function returns the maximum of the values over the requested axis. Syntax: dataframe.max(axis) where, axis=0 specifies columnaxis=1 specifies rowExample 1: Get maximum value in dataframe row To get the maximum value in a dataframe row simply call the max() function with axis set 2 min read Find the sum and maximum value of the two column in excel file using Pandas In these articles, we will discuss how to read data from excel and perform some mathematical operation and store it into a new column in DataFrame. Suppose our excel file looks like this. sample_data.xlsx Then we have to compute the sum of two-column and find out the maximum value and store into a n 2 min read How to Get the minimum value from the Pandas dataframe in Python? In this article, we will discuss how to get the minimum value from the Pandas dataframe in Python. We can get the minimum value by using the min() function Syntax: dataframe.min(axis) where, axis=0 specifies columnaxis=1 specifies rowGet minimum value in dataframe row To get the minimum value in a 2 min read Like