Created
June 20, 2017 04:30
-
-
Save dattgoswami/201c0858b09abd4d564ccc8f609fa0aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "metadata": { | |
| "name": "", | |
| "signature": "sha256:b3555aaf2fdc56e13fc11db217d7e44d797ca20442b73f18c9a83eefb709d0f3" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "cd \\users\\chaitu\\Desktop" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "/Users/chaitu/Desktop\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 3 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "import pandas as pd\n", | |
| "from pandas import *\n", | |
| "import numpy as np\n", | |
| "import csv\n", | |
| "import datetime\n", | |
| "import matplotlib.pyplot as plt\n", | |
| "\n", | |
| "cities = ['ALBANY', 'ANNAPOLIS', 'ATLANTA', 'AUGUSTA', 'AUSTIN', 'BATON ROUGE', 'BISMARCK',\n", | |
| " 'BOISE', 'BOSTON', 'CARSON CITY', 'CHARLESTON', 'CHEYENNE', 'COLUMBIA',\n", | |
| " 'COLUMBUS', 'CONCORD', 'DENVER', 'DES MOINES', 'DOVER', 'FRANKFORT',\n", | |
| " 'HARRISBURG', 'HARTFORD', 'HELENA', 'HONOLULU', 'INDIANAPOLIS', 'JACKSON',\n", | |
| " 'JEFFERSON CITY', 'JUNEAU', 'LANSING', 'LINCOLN', 'LITTLE ROCK', 'MADISON',\n", | |
| " 'MONTGOMERY', 'MONTPELIER', 'NASHVILLE', 'OKLAHOMA CITY', 'OLYMPIA', 'PHOENIX',\n", | |
| " 'PIERRE', 'PROVIDENCE', 'RALEIGH', 'RICHMOND', 'SACRAMENTO', 'SAINT PAUL',\n", | |
| " 'SALEM', 'SALT LAKE CITY', 'SANTA FE', 'SPRINGFIELD', 'TALLAHASSEE', 'TOPEKA',\n", | |
| " 'TRENTON']" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 4 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "rawData = {}\n", | |
| "for city in cities:\n", | |
| " cityData = pd.read_csv(city+'.csv',index_col=0, usecols=[0, 'SNOW'], parse_dates=True)\n", | |
| " cityData.columns = [city]\n", | |
| " rawData[city] = cityData" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 5 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "data = rawData.values()[0].join(rawData.values()[1:], how='outer')\n", | |
| "startDate = data.index[0]\n", | |
| "endDate = data.index[-1]\n", | |
| "if endDate < startDate:\n", | |
| " endDate = startDate\n", | |
| "xmasIndicies = pd.date_range(start=startDate, end=endDate, freq='A').to_series().shift(periods=-1,freq='6D').index\n", | |
| "data = data.reindex(index=xmasIndicies)\n", | |
| "data = data.sort_index(axis=1)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 6 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "snowRawData = {}\n", | |
| "for city in cities:\n", | |
| " cityData = pd.read_csv(city+'.csv',index_col=0, usecols=[0, 'TMIN'], parse_dates=True)\n", | |
| " cityData.columns = [city]\n", | |
| " snowRawData[city] = cityData" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 7 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "snowdata = snowRawData.values()[0].join(snowRawData.values()[1:], how='outer')\n", | |
| "startDate = snowdata.index[0]\n", | |
| "endDate = snowdata.index[-1]\n", | |
| "if endDate < startDate:\n", | |
| " endDate = startDate\n", | |
| "xmasIndicies = pd.date_range(start=startDate, end=endDate, freq='A').to_series().shift(periods=-1,freq='6D').index\n", | |
| "snowdata = snowdata.reindex(index=xmasIndicies)\n", | |
| "snowdata = snowdata.sort_index(axis=1)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 8 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs = pd.DataFrame()\n", | |
| "for city in cities:\n", | |
| " df = DataFrame(data[city])\n", | |
| " df['TMIN'] = Series(snowdata[city], index=df.index)\n", | |
| " df.columns = [ 'SNWD', 'TMIN']\n", | |
| " for i in range(len(df)):\n", | |
| " dfs = dfs.append(df.irow(i))" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 9 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_montpelier = dfs[5280:5445]\n", | |
| "dfs_montpelier = dfs_montpelier[np.isfinite(dfs_montpelier['SNWD'])]\n", | |
| "dfs_montpelier = dfs_montpelier[np.isfinite(dfs_montpelier['TMIN'])]\n", | |
| "plt.scatter(dfs_montpelier['TMIN'], dfs_montpelier['SNWD'])\n", | |
| "plt.title('Montpelier')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show() " | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 12 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_augusta = dfs[495:660]\n", | |
| "dfs_augusta = dfs_augusta[np.isfinite(dfs_augusta['SNWD'])]\n", | |
| "dfs_augusta = dfs_augusta[np.isfinite(dfs_augusta['TMIN'])]\n", | |
| "plt.scatter(dfs_augusta['TMIN'], dfs_augusta['SNWD'])\n", | |
| "plt.title('Augusta')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show() " | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 11 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_saintpaul = dfs[6930:7095]\n", | |
| "dfs_saintpaul = dfs_saintpaul[np.isfinite(dfs_saintpaul['SNWD'])]\n", | |
| "dfs_saintpaul = dfs_saintpaul[np.isfinite(dfs_saintpaul['TMIN'])]\n", | |
| "plt.scatter(dfs_saintpaul['TMIN'], dfs_saintpaul['SNWD'])\n", | |
| "plt.title('Saint Paul')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 13 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_bismarck = dfs[990:1155]\n", | |
| "dfs_bismarck = dfs_bismarck[np.isfinite(dfs_bismarck['SNWD'])]\n", | |
| "dfs_bismarck = dfs_bismarck[np.isfinite(dfs_bismarck['TMIN'])]\n", | |
| "plt.scatter(dfs_bismarck['TMIN'], dfs_bismarck['SNWD'])\n", | |
| "plt.title('Bismarck')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show() " | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 14 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_concord = dfs[2310:2475]\n", | |
| "dfs_concord = dfs_concord[np.isfinite(dfs_concord['SNWD'])]\n", | |
| "dfs_concord = dfs_concord[np.isfinite(dfs_concord['TMIN'])]\n", | |
| "plt.scatter(dfs_concord['TMIN'], dfs_concord['SNWD'])\n", | |
| "plt.title('Concord')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 15 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "dfs_lansing = dfs[4455:4620]\n", | |
| "dfs_lansing = dfs_lansing[np.isfinite(dfs_lansing['SNWD'])]\n", | |
| "dfs_lansing = dfs_lansing[np.isfinite(dfs_lansing['TMIN'])]\n", | |
| "plt.scatter(dfs_lansing['TMIN'], dfs_lansing['SNWD'])\n", | |
| "plt.title('Lansing')\n", | |
| "plt.xlabel('Minimum Temperature')\n", | |
| "plt.ylabel('Snow Depth')\n", | |
| "plt.show()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 16 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment