{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = pd.read_csv('precip_yearly.csv')" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "year\n", "1987 17.095966\n", "1988 21.516704\n", "1989 26.196590\n", "1990 20.638263\n", "1991 21.751607\n", "1992 23.097024\n", "1993 40.622674\n", "1994 19.654803\n", "1995 49.356450\n", "1996 34.819709\n", "1997 35.984432\n", "1998 48.131613\n", "1999 27.392222\n", "2000 28.576508\n", "2001 20.214118\n", "2002 23.192717\n", "2003 30.315964\n", "2004 22.152847\n", "2005 37.733113\n", "2006 41.684191\n", "2007 18.828722\n", "2008 22.283302\n", "2009 23.027718\n", "2010 28.742391\n", "2011 38.864394\n", "2012 21.240446\n", "2013 20.997228\n", "2014 15.341224\n", "Name: precip, dtype: float64" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby('year').precip.mean()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "years, precip = _.index.values, _.values" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,\n", " 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,\n", " 2009, 2010, 2011, 2012, 2013, 2014])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "years" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([ 17.09596591, 21.51670391, 26.1965896 , 20.63826347,\n", " 21.75160714, 23.09702381, 40.62267442, 19.65480263,\n", " 49.3564497 , 34.8197093 , 35.98443243, 48.1316129 ,\n", " 27.39222222, 28.57650794, 20.21411765, 23.19271676,\n", " 30.31596386, 22.15284672, 37.73311258, 41.68419118,\n", " 18.8287218 , 22.28330189, 23.02771812, 28.7423913 ,\n", " 38.86439394, 21.24044643, 20.99722772, 15.34122449])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "precip" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [], "source": [ "np.savez('mean_ca_precip.npz', years=years, precip=precip)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }