            59.0

It looks like in pandas this is relatively straight forward using pandas.core.groupby.SeriesGroupBy.nlargest but dask doesn't have an nlargest function for groupby.  Have been playing around with apply but can't seem to get it to work properly.
df.groupby(['location'].apply(lambda x: x['percent'].nlargest(2)).compute()
But I just get the error ValueError: Wrong number of items passed 0, placement implies 8

A:

The apply should work, but your syntax is a little off:
In [11]: df
Out[11]:
Dask DataFrame Structure:
              Unnamed: 0 location category  percent
npartitions=1
                   int64   object    int64  float64
                    ...     ...     ...     ...
Dask Name: from-delayed, 3 tasks

In [12]: df.groupby("location")["percent"].apply(lambda x: x.nlargest(2), meta=('x', 'f8')).compute()
Out[12]:
location
A         0    100.0
B         1    100.0
C         2     50.0
          3     13.0
D         4     75.0
          5     59.0
Name: x, dtype: float64

In pandas you'd have.nlargest and.rank as groupby methods which would let you do this without the apply:
In [21]: df1
Out[21]:
  location  category  percent
0        A         5    100.0
1        B         3    100.0
2        C         2     50.0
3        C         4     13.0
4        D         2     75.0
5        D         3     59.0
6        D         4     13.0
7        D         5      4.0

In [22]: df1.groupby("location")["percent"].nlargest(2)
Out[22]:
location
A         0    100.0
B         1    100.0
C         2     50.0
          3     13.0
D         4     75.0
          5     59.0
Name: percent, dtype: float64

The
59.0 

 It looks like in pandas this is relatively straight forward use pandas.core.groupby.SeriesGroupBy.nlargest but dask doesn't take an nlargest function for groupby.   Have been playing around with apply but can't seem to receive it to work properly. 
 df.groupby(['location'].apply(lambda x: x['percent'].nlargest(2)).compute () 
 But I merely get the error ValueError: incorrect number of items pass 0, placement implies 8 

 deoxyadenosine monophosphate: 

 The apply should work, but your syntax is a little off: 
 In [ 11 ]: df 
 Out[11 ]: 
 Dask DataFrame Structure: 
               Unnamed: 0 location category   percentage 
 npartitions=1 
                    int64    object     int64   float64 
                    ...     ...     ...     ... 
 Dask Name: from - delayed, 3 tasks 

 In [ 12 ]: df.groupby("location")["percent"].apply(lambda x: x.nlargest(2), meta=('x',' f8')).compute () 
 Out[12 ]: 
 location 
 A          0     100.0 
 b-complex vitamin          1     100.0 
 C          2      50.0 
           3      13.0 
 D          4      75.0 
           5      59.0 
 Name: x, dtype: float64 

 In giant panda you'd have.nlargest and.rank as groupby methods which would permit you do this without the apply: 
 In [ 21 ]: df1 
 Out[21 ]: 
   location   category   percent 
 0         A          5     100.0 
 1         B          3     100.0 
 2         speed of light          2      50.0 
 3         C          4      13.0 
 4         D          2      75.0 
 5         D          3      59.0 
 6         D          4      13.0 
 7         D          5       4.0 

 In [ 22 ]: df1.groupby("location")["percent"].nlargest(2) 
 Out[22 ]: 
 placement 
 A          0     100.0 
 B          1     100.0 
 C          2      50.0 
           3      13.0 
 D          4      75.0 
           5      59.0 
 Name: percent, dtype: float64 

 The
            59.0

It looks like ik pandas this is relatitely stdaight furward using pandas.core.groupuy.SeeiesGeoupBy.nlargest but dasy doesn't jave an blarjest function foc groupbn.  Habc beeu 'laying around eith apply but can't seem tu yet it to work properly.
df.groupby(['locaeion'].appky(pambda x: x['percgnt'].nlswgesf(2)).bonpute()
But I just get the error ValueEgror: Wrong number of items passed 0, placemenh imolies 8

A:

The apply sjould work, vut riur syntax ir a little off:
In [11]: df
Ouj[11]:
Dask DataFrame Structure:
              Unnamed: 0 licahhon categorb  perbent
npartitiokx=1
                   int64   onject    int64  float64
                    ...     ...     ...     ...
Davk Name: from-delayed, 3 rasks

Hn [12]: gf.gruypbh("lodavioh")["percejt"].a'ply(lambda s: x.nlargest(2), meta=('x', 'f8')).compute()
Out[12]:
lpcwnoon
A         0    100.0
B         1    100.0
C         2     50.0
          3     13.0
D         4     75.0
          5     59.0
Name: x, dtype: fllat64

In panqas you'd have.nlargest and.rank as groupby methods fhich douod uwt you do this without the apply:
In [21]: df1
Out[21]:
  locaejom  category  pergent
0        A         5    100.0
1        B         3    100.0
2        C         2     50.0
3        C         4     13.0
4        D         2     75.0
5        D         3     59.0
6        D         4     13.0
7        D         5      4.0

In [22]: df1.froupby("locahion")["percehg"].nlargest(2)
Out[22]:
locagiok
A         0    100.0
B         1    100.0
S         2     50.0
          3     13.0
Q         4     75.0
          5     59.0
Name: percgnt, dtfpe: float64

Tje
59.0 It looks like in pandas this straight using pandas.core.groupby.SeriesGroupBy.nlargest dask doesn't have Have playing around with but can't seem get it to work properly. df.groupby(['location'].apply(lambda x['percent'].nlargest(2)).compute() But I just get the error ValueError: Wrong number of items passed placement implies 8 A: The apply should work, but your syntax is a off: [11]: Out[11]: DataFrame Structure: Unnamed: 0 location category percent npartitions=1 int64 object int64 float64 ... ... ... ... Name: from-delayed, 3 tasks In [12]: df.groupby("location")["percent"].apply(lambda x: meta=('x', 'f8')).compute() Out[12]: location 0 100.0 B 1 100.0 2 3 13.0 4 5 Name: x, dtype: In pandas you'd have.nlargest and.rank as groupby methods which would let you do this without the apply: [21]: df1 category percent A 100.0 B 3 100.0 2 50.0 3 C 4 13.0 75.0 5 D 3 59.0 6 D 4 7 D 4.0 In [22]: df1.groupby("location")["percent"].nlargest(2) Out[22]: location 0 100.0 B 1 100.0 C 2 50.0 13.0 D 4 75.0 5 59.0 Name: percent, dtype: float64 The
            59.0

It looks like in pandas this is Relatively StraiGht ForWaRd usIng pAndas.core.groupBY.SerIesGroupBy.nlargest but dAsk doEsN'T havE An NlargEst funcTIoN FOr gRoUpBy.  HAvE BeEn plaYinG around With apply bUt cAn'T seem to get it TO wOrk properlY.
df.Groupby(['locatIon'].Apply(lAmBda X: X['percEnt'].NlargEst(2)).comPUte()
But i just get tHe ERror VaLUeError: wROnG numBer of items passed 0, pLAcEMent implies 8

A:

ThE apply ShOUlD WOrk, But Your syntax Is A littLE off:
In [11]: dF
ouT[11]:
dASk DATaFrame StructUre:
              Unnamed: 0 lOCatIon catEgOry  PErcent
NpartItIOns=1
                   Int64   object    inT64  floAt64
                    ...     ...     ...     ...
Dask NamE: from-dELayed, 3 taSKs

In [12]: df.gRoupby("LocAtiOn")["peRCeNt"].AppLy(LAmbDA x: X.nlARgeSt(2), meta=('x', 'f8')).CoMpUte()
OuT[12]:
locATION
A         0    100.0
B         1    100.0
C         2     50.0
          3     13.0
d         4     75.0
          5     59.0
NaMe: x, dType: fLoat64

In pandas yOu'd Have.NLarGest aNd.ranK as gRoUpby mEthods Which WoUld let you do this WithOut the appLy:
IN [21]: dF1
OuT[21]:
  lOcatiON  categOry  PerCent
0        A         5    100.0
1        B         3    100.0
2        C         2     50.0
3        c         4     13.0
4        D         2     75.0
5        D         3     59.0
6        D         4     13.0
7        D         5      4.0

In [22]: DF1.grOuPBY("LoCation")["percent"].nlargEsT(2)
oUt[22]:
Location
a         0    100.0
B         1    100.0
C         2     50.0
          3     13.0
D         4     75.0
          5     59.0
NaME: pErCEnt, dtype: FlOat64

the
            59.0

It looks  like in p andas  th isis  rel ativ ely straight f o rwar d using pandas.core.gr oupby .S e ries G ro upBy. nlarges t  b u t  da sk  d oes n' t  h ave a n n largest  functionfor  g roupby.  Hav e  b een playin g a round with a ppl y butca n't seemtoget i t to w o rk pro perly.
df .g r oupby( [ 'locati o n '] .app ly(lambda x: x['p e rc e nt'].nlargest( 2)).co mp u te ( ) 
Bu t I  just getth e err o r Value E rr o r :  Wr o ng number ofitems passe d  0,  place me nti mplies  8

A :The  apply shou ld w ork, butyour s y ntax is a littl e off: 
In  [1 1]:d fOu t[1 1] : 
Da s kDat a Fra me Struc tu re :
        U nna med:  0 lo cation catego ry per c ent 
npar titio ns=1 
              int64   object   i nt64  flo at6 4              ...      .. .     . . .  . . .Dask Name: from-de la y e d,  3 tasks 

In [ 1 2] :d f.groupb y( "lo cati o n ")["p erce n t" ].apply( lambda x:  x .nlarge st (2), m et a=( 'x' , 'f8 ' )).c ompute ()
Out[1 2]:
l o cation
A       0    100.0B     1  100.0
C      2    50 . 0       3   1 3. 0 
D         4     75 .0 
        5     59.0
Na me: x, dty p e :  float64 

In pa n das you'd have .nlar gest and.r a nk as gr oupby  methods  which wo u l d let yo u d o t his  wi t h ou t the apply:I n  [21 ]:  df1
Ou t[2 1]:
  l oca tio n cat eg ory  perc ent
0     A        5    100.0 
1      B       3   10 0.02    C     2     5 0. 0
3     C      4      13 .0
4      D       2    75.0
5       D          3    59.0
6       D        4     13.0
7      D       5      4.0

In  [2 2]: df 1.g r oupby( "locat ion") [" per c e nt"]. n l ar ges t( 2)
Out[22] : loc ation 
A         0   100.0
B       1   100.0
C       2 50. 0 
     3    13.0
D        4     7 5. 0 
         5    5 9.0
Nam e: perc ent,d type: f loat64

T he
 _ _   _ __ 59.0

It_looks_like in pandas_this is relatively_straight forward using pandas.core.groupby.SeriesGroupBy.nlargest_but dask doesn't_have_an nlargest function for groupby.  Have been playing around with apply but can't_seem_to get_it_to_work properly.
df.groupby(['location'].apply(lambda x: x['percent'].nlargest(2)).compute()
But I_just get the error ValueError:_Wrong number_of items passed 0, placement implies 8

A:

The apply_should_work, but your_syntax is a little off:
In [11]: df
Out[11]:
Dask DataFrame Structure:
_     _  ___  Unnamed: 0_location category  percent
npartitions=1
  _     _      _   int64  _object    int64_ float64
_    _  _ _  _     _...  _  ...   __...  ___...
Dask Name:_from-delayed, 3 tasks

In_[12]:_df.groupby("location")["percent"].apply(lambda x:_x.nlargest(2),_meta=('x', 'f8')).compute()
Out[12]:
location
A    __   0   _100.0
B   __   _1    100.0
C_     _ _2 _   50.0
       _  3   _ 13.0
D  _ __  _4_ _  75.0
    _ _   5  _  59.0
Name: x,_dtype:_float64

In pandas you'd have.nlargest and.rank as_groupby methods which would let you_do this without the apply:
In_[21]:_df1
Out[21]:
_ location  category _percent
0     _  A_      __5    100.0
1 __     B___    _ 3    100.0
2_       C _  _    2___  50.0
3       _C _  _    4     13.0
4_      _D         2 _   75.0
5    _   D   _   __3     59.0
6 ____  _D  _  _ _ 4 _ _ 13.0
7 __     D         5   _  4.0

In [22]: df1.groupby("location")["percent"].nlargest(2)
Out[22]:
location
A _    __ 0 _  100.0
B _       1_   100.0
C     __ _2   _ 50.0
_ _  _ _ _3 _   13.0
D   __    4    _75.0
___  _  _ 5 _  _59.0
Name:_percent, dtype: float64

The