pan01

def test_for_longer():
    data = [{'foo': 'GD-20190101-010101', 'son': 'GD-123'},
            {'foo': 'GD-20190101-010101', 'son': 'GD-12345'},
            {'foo': 'GD-20190101-010102', 'son': 'GD-123'},
            {'foo': 'GD-20190101-010102', 'son': 'GD-123456'}]
    df = pd.DataFrame(data)
    df['size'] = df['son'].str.len()
    # df['size'] = df.apply(lambda x: len(x['son']), axis=1)
    idx = df.groupby('foo')['size'].idxmax()
    return df.loc[idx, ['foo', 'son']]
 
 
if __name__ == '__main__':
    val = test_for_longer()
    print(val)