import pandas as pd
df = pd.read_csv('precip_yearly.csv')
df.groupby('year').precip.mean()
year 1987 17.095966 1988 21.516704 1989 26.196590 1990 20.638263 1991 21.751607 1992 23.097024 1993 40.622674 1994 19.654803 1995 49.356450 1996 34.819709 1997 35.984432 1998 48.131613 1999 27.392222 2000 28.576508 2001 20.214118 2002 23.192717 2003 30.315964 2004 22.152847 2005 37.733113 2006 41.684191 2007 18.828722 2008 22.283302 2009 23.027718 2010 28.742391 2011 38.864394 2012 21.240446 2013 20.997228 2014 15.341224 Name: precip, dtype: float64
years, precip = _.index.values, _.values
years
array([1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014])
precip
array([ 17.09596591, 21.51670391, 26.1965896 , 20.63826347, 21.75160714, 23.09702381, 40.62267442, 19.65480263, 49.3564497 , 34.8197093 , 35.98443243, 48.1316129 , 27.39222222, 28.57650794, 20.21411765, 23.19271676, 30.31596386, 22.15284672, 37.73311258, 41.68419118, 18.8287218 , 22.28330189, 23.02771812, 28.7423913 , 38.86439394, 21.24044643, 20.99722772, 15.34122449])
import numpy as np
np.savez('mean_ca_precip.npz', years=years, precip=precip)