-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
29 lines (21 loc) · 759 Bytes
/
Copy pathtest.py
File metadata and controls
29 lines (21 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
import numpy as np
def something():
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
axis=1)
df.iloc[0, 2] = np.nan
var = df.style.apply(highlight_greaterthan_1, axis=1).render()
print(var)
def highlight_greaterthan(s, column):
is_max = pd.Series(data=False, index=s.index)
is_max[column] = s.loc[column] >= 1
return ['background-color: red' if is_max.any() else '' for v in is_max]
def highlight_greaterthan_1(s):
if s.B > 1.0:
return ['background-color: yellow'] * 5
else:
return ['background-color: white'] * 5
if __name__ == '__main__':
something()