0

I have dataset like

df = pd.DataFrame({"type" :["A","B","C","A","B","B"], "value": [40,25,33,22,45,62]})

I want to find each individual type mean, ie., type = A has mean of 31 I did by subsetting

df_a = df.loc[df['type']=="A"]
df_a['value'].mean()

I want to do it in single line, Thanks in advance

1 Answers1

1

A possible solution might be:

df.gropuby('type')['value'].mean()
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Andre S.
  • 478
  • 4
  • 13