0
State/Territory Date    Employment Rate (15-64) Unemployment Rate (15+)
NSW 1978-02-01  n/a     6.8
NSW 1978-03-01  n/a     6.5
NSW 1978-04-01  63.7    6.5
NSW 1978-05-01  63.7    6.1
NSW 1978-06-01  63.7    6.4
NSW 1978-07-01  63.7    6.1
NSW 1978-08-01  63.5    6.3
NSW 1978-09-01  63.5    6.3
NSW 1978-10-01  63.5    6.1
NSW 1978-11-01  63.5    6.2
NSW 1978-12-01  63.8    6.0
NSW 1979-01-01  63.4    5.9
NSW 1979-02-01  63.5    5.9
NSW 1979-03-01  63.3    6.2
NSW 1979-04-01  63.5    6.4
NSW 1979-05-01  63.3    6.2
NSW 1979-06-01  63.2    6.2
NSW 1979-07-01  63.3    6.2
NSW 1979-08-01  63.4    5.5
NSW 1979-09-01  63.7    5.6
NSW 1979-10-01  63.9    5.9
NSW 1979-11-01  64.3    5.5

This is my data and Now I want to calculate average unemployment for each quarter for each state. Is there way to do it?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • just add a new column to identify the quarter. – Harper Koo Apr 11 '18 at 09:20
  • I never tried this. But you can refer this question : [change new ...](https://stackoverflow.com/questions/22681534/java-change-system-new-line-character?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Mudassir Rehman Apr 11 '18 at 09:30
  • Possible duplicate of [TimeSeries with a groupby in Pandas](https://stackoverflow.com/questions/20805299/timeseries-with-a-groupby-in-pandas) – Abbas Apr 11 '18 at 09:34

1 Answers1

3

convert date to datetime type extract quarter then groupby:

In [7]: df['Date'] = pd.to_datetime(df['Date'])
In [10]: df['quarter'] = df.Date.dt.quarter

In [11]: df.groupby(['quarter','State/Territory'])['UnemploymentRate(15+)'].mean()
Out[11]: 
quarter  State/Territory
1        NSW                6.26
2        NSW                6.30
3        NSW                6.00
4        NSW                5.94
Name: UnemploymentRate(15+), dtype: float64
shivsn
  • 7,680
  • 1
  • 26
  • 33