Python Forum
highlighting maximum value dataframe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: highlighting maximum value dataframe (/thread-15449.html)



highlighting maximum value dataframe - PolskaYBZ - Jan-17-2019

Hello,

I am reading through a book about data analysis where I got stuck with an excercice in which I need to highlight the maximum value of each column in a pandas Dataframe.



After I removed all the unneccesary data in a Dataframe, I need to perform the last 3 steps ;


1. Use the idxmax method to find the index label of the maximum value for each column.

max_cols = college_n2.idxmax()
max_cols
Output:
SATVRMID California Institute of Technology SATMTMID California Institute of Technology UGDS University of Phoenix-Arizona UGDS_WHITE Mr Leon's School of Hair Design-Moscow ... PCTFLOAN ABC Beauty College Inc UG25ABV Dongguk University-Los Angeles MD_EARN_WNE_P10 Medical College of Wisconsin GRAD_DEBT_MDN_SUPP Southwest University of Visual Arts-Tucson
Length: 18, dtype: object

2. Call the unique method afterwards on the max_cols Series,
unique_max_cols = max_cols.unique()
unique_max_cols[:5]
Output:
array(['California Institute of Technology', 'University of Phoenix-Arizona', "Mr Leon's School of Hair Design-Moscow", 'Velvatex College of Beauty Culture', 'Thunderbird School of Global Management'], dtype=object)
3. Afterwards, the values of unique_max_cols will be passed in the dataframe to select and highlight the maximum value.

college_n2.loc[unique_max_cols].style.highlight_max()
I understand the first step, but I do not fully understand why in step 2 I need to select only the unique values and how then anyway in step 3 they are able to select the maximum values.

Some clarification would be much appreciated.

Thank you.