I dont understand what is the logic behind the output

Viewed 25

I have created a DataFrame (df): Dataframe

when i add another line of code that goes as : print(df[df.C2>10].max()['C1'])

output: output

The output given is 12 Can someone please explain to me why is the output 12 and how is that coming up please.

1 Answers
>>> df=pd.DataFrame(columns=['C1','C2','C3'], index=['r1', 'r2','r3'], data=[[11, 19,20],[22,5,6],[12,15,16]])
>>> df[df.C2>10]
    C1  C2  C3
r1  11  19  20
r3  12  15  16
>>> df[df.C2>10].max()
C1    12
C2    19
C3    20
dtype: int64
>>> df[df.C2>10].max()['C1']
12
>>> 

df[df.C2>10] selects the rows, where C2 is greater than 10

.max() calculates the maximum over all rows for each column

['C1'] selects column C1

Related