简体   繁体   中英

how to find max value in groupby python dataframe

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

I want to get this

Is this what you want?

fig, ax = plt.subplots()
for key, grp in df.groupby(['A','B','DC']):
        ax = grp.plot(ax=ax, kind='line', x='score', y='max_sel', label=key, marker='o')

gives you the following result:

用同一图中的线绘制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM