0

I have a DataFrame shown below with sector, duration and cost.

example, this is the start of the dataframe

Sector Duration Cost
Construction 23.300000 3.5382
Construction 24.333333 3.0774
Health 43.600000 1.0830
Health 23.300000 1.6543
Sports 33.466667 7.2511

I'd like to group by Sector and that columns show the duration based in quintiles of the variable cost. something like

Resultado final

I have tried the following

def q1(x):  
return x.quantile(0.2)
def q2(x):
return x.quantile(0.40)
def q3(x):
return x.quantile(0.60)
def q4(x):
return x.quantile(0.8)

vals = {"Duration": [q1, q2, q3, q4, q5]}
df_1 = proy.groupby("Sector").agg(vals)

but it gets quintiles of duration and not duration based in quintiles of cost.

eshirvana
  • 23,227
  • 3
  • 22
  • 38
  • Does this answer your question? [Pandas groupby quantile values](https://stackoverflow.com/questions/47637774/pandas-groupby-quantile-values) – sophocles Nov 30 '22 at 14:57

0 Answers0