Skip to content

Commit

Permalink
Adds code to compute state summaries...
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpfay committed Oct 26, 2017
1 parent 4ff10c4 commit 13ac99f
Showing 1 changed file with 78 additions and 36 deletions.
114 changes: 78 additions & 36 deletions Scripts/DiscontinuedFiles/CreateSupplyTable.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Import libraries\n",
Expand All @@ -48,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -62,7 +64,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -111,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -213,28 +215,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"->Downloading runoff data for year 2000 ...**complete!**\n",
"->Downloading et data for year 2000 ...**complete!**\n",
"->Downloading precip data for year 2000 ...**complete!**\n",
"->Downloading soil data for year 2000 ...**complete!**\n",
"->Downloading runoff data for year 2005 ...**complete!**\n",
"->Downloading et data for year 2005 ...**complete!**\n",
"->Downloading precip data for year 2005 ...**complete!**\n",
"->Downloading soil data for year 2005 ...**complete!**\n",
"->Downloading runoff data for year 2010 ...**complete!**\n",
"->Downloading et data for year 2010 ...**complete!**\n",
"->Downloading precip data for year 2010 ...**complete!**\n",
"->Downloading soil data for year 2010 ...**complete!**\n"
]
}
],
"outputs": [],
"source": [
"#Retrieve data frames for each sample year, using the function above\n",
"df2000 = getSupplyData(2000)\n",
Expand All @@ -244,10 +227,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Use the addFIPS function to add FIPS values to the table\n",
Expand All @@ -258,7 +239,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -270,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -283,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -304,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -316,7 +297,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -328,7 +309,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -337,6 +318,67 @@
"#Write the table to the file\n",
"dfCounty.to_csv(outputFN,encoding='utf8',index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dfCounty.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Summarize by state\n",
"dfState = dfCounty.groupby(('YEAR','STATEFIPS'))['Supply'].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stateSummary = dfState.unstack().T\n",
"stateSummary.to_csv('../../Data/StateSupply.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import us"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stateSummary.reset_index(inplace=True)\n",
"stateSummary['MGALperDay'] = stateSummary['STATEFIPS'].apply(lambda x: us.states.lookup(x))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stateSummary[['MGALperDay',2000,2005,2010]].to_csv('../../Data/StateSupply.csv',index=False)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 13ac99f

Please sign in to comment.