mirror of
https://github.com/balkian/gists.git
synced 2024-12-22 14:28:12 +00:00
Add 'repos/41c51d1a6f6d4277c6cee5a92b8ba6d1/' from commit '64e480b163ea434411eb659e5374eb0b50c9c318'
git-subtree-dir: repos/41c51d1a6f6d4277c6cee5a92b8ba6d1 git-subtree-mainline:dcba36b566
git-subtree-split:64e480b163
This commit is contained in:
commit
34b0ce1eef
24
repos/41c51d1a6f6d4277c6cee5a92b8ba6d1/pandalatex.py
Normal file
24
repos/41c51d1a6f6d4277c6cee5a92b8ba6d1/pandalatex.py
Normal file
@ -0,0 +1,24 @@
|
||||
def latex_max(data, bgcolor='yellow', fgcolor="black", ignore=['AvgContent',]):
|
||||
'''
|
||||
highlight the maximum in a Series or DataFrame
|
||||
'''
|
||||
txt = '{:.3f}'
|
||||
attr = '\textbf{{{}}}'
|
||||
attr_max = '\colorbox{{' + bgcolor + '}}{{\textcolor{{' + fgcolor + '}}{{{}}}}}'
|
||||
# print(data)
|
||||
is_max = data >= data.drop(ignore).max()
|
||||
mx = data.drop(ignore).max()
|
||||
real_mx = data.max()
|
||||
attrs = []
|
||||
for v in data:
|
||||
a = txt.format(v)
|
||||
if v == mx:
|
||||
a = attr.format(a)
|
||||
if v == real_mx:
|
||||
a = attr_max.format(a)
|
||||
attrs.append(a)
|
||||
return pd.Series(attrs, index=data.index)
|
||||
|
||||
def to_latex(df, *args, **kwargs):
|
||||
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.max_colwidth', -1):
|
||||
print(df.apply(lambda x: latex_max(x, *args, **kwargs), axis=1).to_latex(escape=False))
|
Loading…
Reference in New Issue
Block a user