Highlight Pandas DataFrame’s specific columns using apply() Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report Let us see how to highlight specific columns of a Pandas DataFrame. We can do this using the apply() function of the Styler class. Styler.apply() Syntax : Styler.apply(func, axis = 0, subset = None, **kwargs) Parameters : func : function should take a Series or DataFrame (depending on-axis), and return an object with the same shape. Must return a DataFrame with identical index and column labels when axis = None. axis : apply to each column (axis=0 or ‘index’) or to each row (axis=1 or ‘columns’) or to the entire DataFrame at once with axis = None subset : valid indexer to limit data to before applying the function. **kwargs : dict pass along to func. Returns : Styler Let’s understand with examples: Example 1 : # importing pandas as pd import pandas as pd # creating the dataframe df = pd.DataFrame({"A" : [14, 4, 5, 4, 1], "B" : [5, 2, 54, 3, 2], "C" : [20, 20, 7, 3, 8], "D" : [14, 3, 6, 2, 6], "E" : [23, 45, 64, 32, 23]}) print("Original DataFrame :") display(df) # function definition def highlight_cols(x): # copy df to new - original data is not changed df = x.copy() # select all values to green color df.loc[:, :] = 'background-color: green' # overwrite values grey color df[['B', 'C', 'E']] = 'background-color: grey' # return color df return df print("Highlighted DataFrame :") display(df.style.apply(highlight_cols, axis = None)) Output : Example 2 : # importing pandas as pd import pandas as pd # creating the dataframe df = pd.DataFrame({"Name" : ["Yash", "Ankit", "Rao"], "Age" : [5, 2, 54]}) print("Original DataFrame :") display(df) # function definition def highlight_cols(x): # copy df to new - original data is not changed df = x.copy() # select all values to yellow color df.loc[:, :] = 'background-color: yellow' # return color df return df print("Highlighted DataFrame :") display(df.style.apply(highlight_cols, axis = None)) Output : Last Updated : 17 Aug, 2020 Like Article Save Article Previous String manipulations in Pandas DataFrame Next Getting Started With Testing in Python Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Highlight Pandas DataFrame's specific columns using applymap() Highlight the maximum value in last two columns in Pandas - Python Apply a function to single or selected columns or rows in Pandas Dataframe Highlight the nan values in Pandas Dataframe Highlight the negative values red and positive values black in Pandas Dataframe Select Columns with Specific Data Types in Pandas Dataframe Pandas DataFrame assign() Method | Create new Columns in DataFrame Return multiple columns using Pandas apply() method Apply a transformation to multiple columns PySpark dataframe How to Apply a function to multiple columns in Pandas? Like kumar_satyam Follow Article Tags : Python pandas-dataFrame Python-pandas Python Practice Tags : python Additional Information Current difficulty : Medium Vote for difficulty : Easy Normal Medium Hard Expert