Last active
July 25, 2016 20:11
-
-
Save MattPitlyk/7fe5d19c0d8d0ac98349a62858a44f05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example pulled from pandas docs for highlights | |
the highest number in each columns to illustrate the | |
experimental DataFrame.style api. | |
""" | |
import pandas as pd | |
df = pd.DataFrame.from_dict({'Medications': {'By Alphabetical': 7.7914173413117429e-05, | |
'By Diagnosis': 0.12608248612763967, | |
'By Occurrences': 0.024339338681789544}, | |
'Procedures': {'By Alphabetical': 0.047130071746056358, | |
'By Diagnosis': 0.61378383651360346, | |
'By Occurrences': 0.47103678987544501}}) | |
def highlight_max(s): | |
''' | |
highlight the maximum in a Series yellow. | |
''' | |
is_max = s == s.max() | |
return ['background-color: yellow' if v else '' for v in is_max] | |
df.applymap(lambda n: "{:.2f}".format(n)).style.apply(highlight_max) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment