Is_max = s == s.max () | How do i read this?

Studying Pandas Style , I realized the following:

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]

How to read is_max = s == s.max()?

+4
source share
5 answers

s == s.max()will be computed before boolean (due to ==between variables). The next step is to save this value in is_max.

+2
source

The code

is_max = s == s.max()

estimated as

is_max = (s == s.max())

First, the bit in parentheses is evaluated, and this is either True, or False. The result is assigned is_max.

+2
source

pandas s Series ( DataFrame).

, Series max Series . is_max. 'background-color: yellow' , True - .

:

s = pd.Series([1,2,3])
print (s)
0    1
1    2
2    3
dtype: int64

is_max = s == s.max()
print (is_max)
0    False
1    False
2     True
dtype: bool
+2

is_max EQUAL s s_max

0

:

, .

, , .

, Python s.max(), , s, , is_max.

. :

0

Source: https://habr.com/ru/post/1657494/


All Articles