1

I have a dataframe that looks like this:

Year    Month    Day    Delay
2019    1        4      60
2018    1        10     50
2018    1        30     25
2019    1        16     42
2017    1        14     0
2019    1        16     9
2017    1        14     5

I want to get the average Delay for each Year.

I think I need to use groupby() but I don't know how to do it for two variables.

In another solution they don't show how to get a variable by grouping.

rachelvsamuel
  • 1,551
  • 2
  • 10
  • 21

1 Answers1

2

IIUC, is it mean?

df.groupby('Year').Delay.mean()

Out[126]:
Year
2017     2.5
2018    37.5
2019    37.0
Name: Delay, dtype: float64
Andy L.
  • 24,909
  • 4
  • 17
  • 29