Home > Software design >  how to find max value in groupby python dataframe
how to find max value in groupby python dataframe

Time:11-14

this is my table for the question.

I want to get a figure with 3 lines.

(legend : aaa_bbb_L, aaa_bbb_Q, aaa_bbb_ZL)

df = pd.DataFrame({ 
'A': ['aaa','aaa','aaa','aaa','aaa','aaa','aaa','aaa','aaa','aaa','aaa','aaa'],
'B': ['bbb','bbb','bbb','bbb','bbb','bbb','bbb','bbb','bbb','bbb','bbb','bbb'],
'DC': ['L','L','L','L','Q','Q','Q','Q','ZL','ZL','ZL','ZL'],
'score' : [0.1,0.2,0.3,0.4,0.11,0.21,0.31,0.39,0.1,0.22,0.3,0.42],
'max_sel' : [2.0,3.3,6.0,7.1,3.1,4.0,8.0,8.9,1.2,3.0,5.0,6.6]
})

df.groupby(["A","B","DC"]).plot(legend = True, xlabel='score', ylabel="max_sel",x="score", y = "max_sel")
plt.show()

I tried but the above code made 3 different figure. how to get the figure like this

Plot with the lines in the same plot

  • Related