简体   繁体   English

如何在groupby python数据帧中找到最大值

[英]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.我想得到一个有 3 行的图。

(legend : aaa_bbb_L, aaa_bbb_Q, aaa_bbb_ZL) (图例: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.我试过了,但上面的代码做了 3 个不同的数字。 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:给你以下结果:

用同一图中的线绘制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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