您只需要
apply在
groupby对象上使用。我修改了示例数据,使其更加清晰:
import pandasfrom io import StringIOcsv = StringIO("""index,A,B0,1,0.01,1,3.02,1,6.03,2,0.04,2,5.05,2,7.0""")df = pandas.read_csv(csv, index_col='index')groups = df.groupby(by=['A'])print(groups.apply(lambda g: g[g['B'] == g['B'].max()]))
哪些打印:
A BA index 1 2 1 62 4 2 7
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)