Highlight Pandas DataFrame's specific columns using applymap() Last Updated : 17 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Let us see how to highlight elements and specific columns of a Pandas DataFrame. We can do this using the applymap() function of the Styler class. Styler.applymap() Syntax : Styler.applymap(self, func, subset = None, **kwargs) Parameters : func : takes a scalar and returns a scalar. subset : valid indexer to limit data to before applying the function. **kwargs : dict pass along to func. Returns : Styler Let's understand with examples: First of all create a simple data frame: python3 # 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]}) print("Original DataFrame :") display(df) Output : Example 1 : For every cell in the DataFrame, if the value is less than 6 then we will highlight the cell with red color, otherwise with blue color. Python3 # function definition def highlight_cols(s): color = 'red' if s < 6 else 'blue' return 'background-color: % s' % color # highlighting the cells display(df.style.applymap(highlight_cols)) Output : Example 2 : This time we will highlight only the cells in some specified columns. Python3 # function definition def highlight_cols(s): return 'background-color: % s' % 'yellow' # highlighting the cells display(df.style.applymap(highlight_cols, subset = pd.IndexSlice[:, ['B', 'C']])) Output : Highlight specific columns with the help of Indexing: Python3 df.style.applymap(highlight_cols, subset = pd.IndexSlice[:, ['B', 'C']]) Comment More infoAdvertise with us Next Article Apply a function to single or selected columns or rows in Pandas Dataframe K kumar_satyam Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads Highlight Pandas DataFrame's specific columns using apply() 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 ret 2 min read Apply uppercase to a column in Pandas dataframe Analyzing a real world data is some what difficult because we need to take various things into consideration. Apart from getting the useful data from large datasets, keeping data in required format is also very important. One might encounter a situation where we need to uppercase each letter in any 2 min read Select Columns with Specific Data Types in Pandas Dataframe In this article, we will see how to select columns with specific data types from a dataframe. This operation can be performed using the DataFrame.select_dtypes() method in pandas module. Syntax: DataFrame.select_dtypes(include=None, exclude=None)Parameters :Â include, exclude : A selection of dtypes 2 min read Apply a function to single or selected columns or rows in Pandas Dataframe In this article, we will learn different ways to apply a function to single or selected columns or rows in Dataframe. We will use Dataframe/series.apply() method to apply a function. Apply a function to single row in Pandas DataframeHere, we will use different methods to apply a function to single r 5 min read Apply a function to each row or column in Dataframe using pandas.apply() Let's explore how to use the apply() function to perform operations on Pandas DataFrame rows and columns.pandas.DataFrame.apply() method is used to apply a function along the axis of a DataFrame (either rows or columns). Syntax: DataFrame.apply(func, axis=0, raw=False, result_type=None, args=None, * 5 min read How to display bar charts in Pandas dataframe on specified columns? In this article we will see how to display bar charts in dataframe on specified columns. For doing this task we are using DataFrame.style.bar() method of Pandas Dataframe. Syntax: pandas.DataFrame.style.bar(columns_list, color) Return: Dataframe with the given color bar strips on the positive defini 1 min read Like