如何在pandas groupby中显示匹配的行

时间:2018-01-05 06:01:14

标签: python pandas pandas-groupby

The dataframe contains

df=
        A   B   C
A
196512  196512    1325  12.9010511000000
196512  196512  114569  12.9267705000000
196512  196512  118910  12.8983353775637
196512  196512  100688  12.9505091000000
196795  196795   28978  12.7805170314276
196795  196795   34591  12.8994111000000
196795  196795   13078  12.9135746000000
196795  196795   24173  12.8769653100000
196341  196341  118910  12.8983353775637
196341  196341  100688  12.9505091000000
196641  196641   28972  12.7805170314276
196641  196641   34591  12.8994111000000
196346  196341  118910  12.8983353775637
196346  196341  100688  12.9505091000000
196646  196641   28980  12.7805170314276
196646  196641   34591  12.8994111000000

I tried to get minimum value for each group and display using the following code,

df.columns = ['a','b','c'] df.index = df.a.astype(str) dd=df.groupby('a').min()['c']

it gives the result

196512    12.7805170314276
196795    12.7805170314276
196341   12.7805170314276
196346   12.7805170314276
but after grouping, I want to get the minimum valued row for each group and display that full matching row in result 
like
196512    118910    12.8983353775637  
196795    28978       12.7805170314276
196341   28972        12.7805170314276
196346   28980        12.7805170314276

0 个答案:

没有答案