Jan-17-2019, 08:49 PM
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.
2. Call the unique method afterwards on the max_cols Series,
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.
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.
1 2 |
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: object2. Call the unique method afterwards on the max_cols Series,
1 2 |
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.1 |
college_n2.loc[unique_max_cols].style.highlight_max() |
Some clarification would be much appreciated.
Thank you.