{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Revising Costs - Paper"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import numpy as np\n",
"import csv\n",
"import os\n",
"import statsmodels.formula.api as sm\n",
"from sklearn.linear_model import LinearRegression"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cost Approach 1 - Simple"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Setting Variables\n",
"wall_average = 218000\n",
"wall_low = 143000\n",
"wall_high = 293000\n",
"\n",
"levee_average = 8000\n",
"levee_low = 4000\n",
"levee_high = 12000\n",
"\n",
"fboard = 0.6096\n",
"\n",
"edf = 1.13"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fresh - Approach 1 - Simple"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"df = pd.read_csv('data/fresh_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\" fresh\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"# multiplying to get cost per segment for the average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"\n",
"# multiplying to get cost per segment for the low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"\n",
"# multiplying to get cost per segment for the high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"fresh_simple = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"fresh_simple = fresh_simple.rename(columns = {\n",
" 'High_Billion':'S_T_H',\n",
" 'High_L_Billion':'S_L_H',\n",
" 'High_W_Billion':'S_W_H',\n",
" 'Low_Billion':'S_T_L',\n",
" 'Low_L_Billion':'S_L_L',\n",
" 'Low_W_Billion':'S_W_L',\n",
" 'Average_Billion': 'S_T_A',\n",
" 'Average_L_Billion': 'S_L_A',\n",
" 'Average_W_Billion': 'S_W_A', })\n",
"\n",
"fresh_simple.to_csv('data/no_storm/fresh_simple.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Salt - Approach 1 - Simple"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"df = pd.read_csv('data/salt_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\" salt\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"# multiplying to get cost per segment for the average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"\n",
"# multiplying to get cost per segment for the low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"\n",
"# multiplying to get cost per segment for the high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"salt_simple = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"salt_simple = salt_simple.rename(columns = {\n",
" 'High_Billion':'S_T_H',\n",
" 'High_L_Billion':'S_L_H',\n",
" 'High_W_Billion':'S_W_H',\n",
" 'Low_Billion':'S_T_L',\n",
" 'Low_L_Billion':'S_L_L',\n",
" 'Low_W_Billion':'S_W_L',\n",
" 'Average_Billion': 'S_T_A',\n",
" 'Average_L_Billion': 'S_L_A',\n",
" 'Average_W_Billion': 'S_W_A', })\n",
"\n",
"salt_simple.to_csv('data/no_storm/salt_simple.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Current - Approach 1 - Simple"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"df = pd.read_csv('data/current_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\" current\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"# multiplying to get cost per segment for the average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave']\n",
"\n",
"# multiplying to get cost per segment for the low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low']\n",
"\n",
"# multiplying to get cost per segment for the high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"current_simple = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"current_simple = current_simple.rename(columns = {\n",
" 'High_Billion':'S_T_H',\n",
" 'High_L_Billion':'S_L_H',\n",
" 'High_W_Billion':'S_W_H',\n",
" 'Low_Billion':'S_T_L',\n",
" 'Low_L_Billion':'S_L_L',\n",
" 'Low_W_Billion':'S_W_L',\n",
" 'Average_Billion': 'S_T_A',\n",
" 'Average_L_Billion': 'S_L_A',\n",
" 'Average_W_Billion': 'S_W_A', })\n",
"\n",
"current_simple.to_csv('data/no_storm/current_simple.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cost Approach 2 - Simple Plus Parcel Cost"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fresh - Approach 2 - Simple Plus Parcel Cost"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array(['Alameda', 'Contra Costa', 'Marin', 'Napa', 'San Francisco',\n",
" 'San Mateo', 'Santa Clara', 'Solano', 'Sonoma'], dtype=object)"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = pd.read_csv('data/no_storm/fresh_parcel.csv')\n",
"df2.county.unique()"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#importing the data\n",
"df2 = pd.read_csv('data/no_storm/fresh_parcel.csv')\n",
"\n",
"#getting the parcel cost factor\n",
"df2.loc[df2['0_SLR_Parcel_Count'] > 0,'0_p_cost'] = df2['0_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['50_SLR_Parcel_Count'] > 0,'50_p_cost'] = df2['50_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['100_SLR_Parcel_Count'] > 0,'100_p_cost'] = df2['100_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['150_SLR_Parcel_Count'] > 0,'150_p_cost'] = df2['150_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['200_SLR_Parcel_Count'] > 0,'200_p_cost'] = df2['200_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['500_SLR_Parcel_Count'] > 0,'500_p_cost'] = df2['500_SLR_Parcel_Count'] * df2['price']\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Geographic','0_p_cost','50_p_cost', '100_p_cost','150_p_cost',\n",
" '200_p_cost','500_p_cost',]]\n",
"\n",
"# adding the index\n",
"df2 = df2.set_index('Geographic')\n",
"\n",
"# transposing\n",
"df2 = df2.T\n",
"\n",
"# getting total & Making into billions\n",
"df2['Parcel'] = df2['Alameda'] + df2['Contra Costa'] + df2['Marin'] + df2['Napa'] + df2['San Francisco'] + df2['San Mateo'] + df2['Santa Clara'] + df2['Solano'] + df2['Sonoma']\n",
"df2['Parcel_B'] = df2['Parcel'] / 1000000000\n",
"df2['Parcel_Billion'] = df2['Parcel_B'] * edf\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Parcel_Billion']]\n",
"\n",
"\n",
"# getting the right info into the index\n",
"df2.reset_index(level=0, inplace=True)\n",
"dic = {'0_p_cost': 0, '50_p_cost': 50, '100_p_cost': 100, '150_p_cost': 150,'200_p_cost': 200, '500_p_cost': 500}\n",
"df2['SLR'] = df2['index'].apply(lambda x: dic[x])\n",
"\n",
"#merging with the simple version\n",
"df3 = pd.merge(df2, fresh_simple, left_on='SLR', right_on='SLR')\n",
"\n",
"#calculating\n",
"df3['S_L_P_A'] = df3['S_L_A'] + df3['Parcel_Billion']\n",
"df3['S_L_P_L'] = df3['S_L_L'] + df3['Parcel_Billion']\n",
"df3['S_L_P_H'] = df3['S_L_H'] + df3['Parcel_Billion']\n",
"\n",
"df3['S_T_P_A'] = df3['S_W_A'] + df3['S_L_P_A']\n",
"df3['S_T_P_L'] = df3['S_W_L'] + df3['S_L_P_L']\n",
"df3['S_T_P_H'] = df3['S_W_H'] + df3['S_L_P_H']\n",
"\n",
"#Limiting\n",
"fsp = df3.loc[:,['SLR','Parcel_Billion','S_T_P_A', 'S_T_P_L', 'S_T_P_H',\n",
" 'S_W_A', 'S_W_L', 'S_W_H',\n",
" 'S_L_P_A','S_L_P_L','S_L_P_H','Leng_Total']]\n",
"\n",
"# exporting\n",
"fsp.to_csv('data/no_storm/fresh_simple_parcel.csv')"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
\n",
" \n",
" \n",
" | \n",
" SLR | \n",
" Parcel_Billion | \n",
" S_T_P_A | \n",
" S_T_P_L | \n",
" S_T_P_H | \n",
" S_W_A | \n",
" S_W_L | \n",
" S_W_H | \n",
" S_L_P_A | \n",
" S_L_P_L | \n",
" S_L_P_H | \n",
" Leng_Total | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 1.232452 | \n",
" 6.987855 | \n",
" 4.822154 | \n",
" 9.153555 | \n",
" 4.565179 | \n",
" 2.994590 | \n",
" 6.135768 | \n",
" 2.422676 | \n",
" 1.827564 | \n",
" 3.017788 | \n",
" 1.369789e+05 | \n",
"
\n",
" \n",
" 1 | \n",
" 50 | \n",
" 7.795651 | \n",
" 23.938357 | \n",
" 17.739435 | \n",
" 30.137279 | \n",
" 12.005587 | \n",
" 7.875225 | \n",
" 16.135950 | \n",
" 11.932770 | \n",
" 9.864210 | \n",
" 14.001329 | \n",
" 3.700907e+05 | \n",
"
\n",
" \n",
" 2 | \n",
" 100 | \n",
" 8.865660 | \n",
" 36.176434 | \n",
" 25.725955 | \n",
" 46.626913 | \n",
" 20.549115 | \n",
" 13.479466 | \n",
" 27.618765 | \n",
" 15.627319 | \n",
" 12.246489 | \n",
" 19.008148 | \n",
" 5.944888e+05 | \n",
"
\n",
" \n",
" 3 | \n",
" 150 | \n",
" 10.606510 | \n",
" 75.175357 | \n",
" 50.735526 | \n",
" 99.615188 | \n",
" 50.297683 | \n",
" 32.993434 | \n",
" 67.601932 | \n",
" 24.877674 | \n",
" 17.742092 | \n",
" 32.013255 | \n",
" 1.138178e+06 | \n",
"
\n",
" \n",
" 4 | \n",
" 200 | \n",
" 11.201620 | \n",
" 101.148820 | \n",
" 67.149777 | \n",
" 135.147862 | \n",
" 70.366282 | \n",
" 46.157699 | \n",
" 94.574866 | \n",
" 30.782537 | \n",
" 20.992078 | \n",
" 40.572996 | \n",
" 1.336005e+06 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SLR Parcel_Billion S_T_P_A S_T_P_L S_T_P_H S_W_A \\\n",
"0 0 1.232452 6.987855 4.822154 9.153555 4.565179 \n",
"1 50 7.795651 23.938357 17.739435 30.137279 12.005587 \n",
"2 100 8.865660 36.176434 25.725955 46.626913 20.549115 \n",
"3 150 10.606510 75.175357 50.735526 99.615188 50.297683 \n",
"4 200 11.201620 101.148820 67.149777 135.147862 70.366282 \n",
"\n",
" S_W_L S_W_H S_L_P_A S_L_P_L S_L_P_H Leng_Total \n",
"0 2.994590 6.135768 2.422676 1.827564 3.017788 1.369789e+05 \n",
"1 7.875225 16.135950 11.932770 9.864210 14.001329 3.700907e+05 \n",
"2 13.479466 27.618765 15.627319 12.246489 19.008148 5.944888e+05 \n",
"3 32.993434 67.601932 24.877674 17.742092 32.013255 1.138178e+06 \n",
"4 46.157699 94.574866 30.782537 20.992078 40.572996 1.336005e+06 "
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fsp.head(n=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Salt - Approach 2 - Simple Plus Parcel Cost"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df2 = pd.read_csv('data/no_storm/salt_parcel.csv')\n",
"\n",
"#getting the parcel cost factor\n",
"df2.loc[df2['0_SLR_Parcel_Count'] > 0,'0_p_cost'] = df2['0_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['50_SLR_Parcel_Count'] > 0,'50_p_cost'] = df2['50_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['100_SLR_Parcel_Count'] > 0,'100_p_cost'] = df2['100_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['150_SLR_Parcel_Count'] > 0,'150_p_cost'] = df2['150_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['200_SLR_Parcel_Count'] > 0,'200_p_cost'] = df2['200_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['500_SLR_Parcel_Count'] > 0,'500_p_cost'] = df2['500_SLR_Parcel_Count'] * df2['price']\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Geographic','0_p_cost','50_p_cost', '100_p_cost','150_p_cost',\n",
" '200_p_cost','500_p_cost',]]\n",
"\n",
"# adding the index\n",
"df2 = df2.set_index('Geographic')\n",
"\n",
"# transposing\n",
"df2 = df2.T\n",
"\n",
"# getting total & Making into billions\n",
"df2['Parcel'] = df2['Alameda'] + df2['Contra Costa'] + df2['Marin'] + df2['Napa'] + df2['San Francisco'] + df2['San Mateo'] + df2['Santa Clara'] + df2['Solano'] + df2['Sonoma']\n",
"df2['Parcel_B'] = df2['Parcel'] / 1000000000\n",
"df2['Parcel_Billion'] = df2['Parcel_B'] * edf\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Parcel_Billion']]\n",
"\n",
"\n",
"# getting the right info into the index\n",
"df2.reset_index(level=0, inplace=True)\n",
"dic = {'0_p_cost': 0, '50_p_cost': 50, '100_p_cost': 100, '150_p_cost': 150,'200_p_cost': 200, '500_p_cost': 500}\n",
"df2['SLR'] = df2['index'].apply(lambda x: dic[x])\n",
"\n",
"#merging with the simple version\n",
"df3 = pd.merge(df2, salt_simple, left_on='SLR', right_on='SLR')\n",
"\n",
"#calculating\n",
"df3['S_L_P_A'] = df3['S_L_A'] + df3['Parcel_Billion']\n",
"df3['S_L_P_L'] = df3['S_L_L'] + df3['Parcel_Billion']\n",
"df3['S_L_P_H'] = df3['S_L_H'] + df3['Parcel_Billion']\n",
"\n",
"df3['S_T_P_A'] = df3['S_W_A'] + df3['S_L_P_A']\n",
"df3['S_T_P_L'] = df3['S_W_L'] + df3['S_L_P_L']\n",
"df3['S_T_P_H'] = df3['S_W_H'] + df3['S_L_P_H']\n",
"\n",
"#Limiting\n",
"ssp = df3.loc[:,['SLR','Parcel_Billion','S_T_P_A', 'S_T_P_L', 'S_T_P_H',\n",
" 'S_W_A', 'S_W_L', 'S_W_H',\n",
" 'S_L_P_A','S_L_P_L','S_L_P_H','Leng_Total']]\n",
"\n",
"# exporting\n",
"ssp.to_csv('data/no_storm/salt_simple_parcel.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Current - Approach 2 - Simple Plus Parcel Cost"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df2 = pd.read_csv('data/no_storm/current_parcel.csv')\n",
"\n",
"#getting the parcel cost factor\n",
"df2.loc[df2['0_SLR_Parcel_Count'] > 0,'0_p_cost'] = df2['0_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['50_SLR_Parcel_Count'] > 0,'50_p_cost'] = df2['50_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['100_SLR_Parcel_Count'] > 0,'100_p_cost'] = df2['100_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['150_SLR_Parcel_Count'] > 0,'150_p_cost'] = df2['150_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['200_SLR_Parcel_Count'] > 0,'200_p_cost'] = df2['200_SLR_Parcel_Count'] * df2['price']\n",
"df2.loc[df2['500_SLR_Parcel_Count'] > 0,'500_p_cost'] = df2['500_SLR_Parcel_Count'] * df2['price']\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Geographic','0_p_cost','50_p_cost', '100_p_cost','150_p_cost',\n",
" '200_p_cost','500_p_cost',]]\n",
"\n",
"# adding the index\n",
"df2 = df2.set_index('Geographic')\n",
"\n",
"# transposing\n",
"df2 = df2.T\n",
"\n",
"# getting total & Making into billions\n",
"df2['Parcel'] = df2['Alameda'] + df2['Contra Costa'] + df2['Marin'] + df2['San Francisco'] + df2['San Mateo'] + df2['Santa Clara'] + df2['Solano'] + df2['Sonoma']\n",
"df2['Parcel_B'] = df2['Parcel'] / 1000000000\n",
"df2['Parcel_Billion'] = df2['Parcel_B'] * edf\n",
"\n",
"#Limiting\n",
"df2 = df2.loc[:,['Parcel_Billion']]\n",
"\n",
"\n",
"# getting the right info into the index\n",
"df2.reset_index(level=0, inplace=True)\n",
"dic = {'0_p_cost': 0, '50_p_cost': 50, '100_p_cost': 100, '150_p_cost': 150,'200_p_cost': 200, '500_p_cost': 500}\n",
"df2['SLR'] = df2['index'].apply(lambda x: dic[x])\n",
"\n",
"#merging with the simple version\n",
"df3 = pd.merge(df2, current_simple, left_on='SLR', right_on='SLR')\n",
"\n",
"#calculating\n",
"df3['S_L_P_A'] = df3['S_L_A'] + df3['Parcel_Billion']\n",
"df3['S_L_P_L'] = df3['S_L_L'] + df3['Parcel_Billion']\n",
"df3['S_L_P_H'] = df3['S_L_H'] + df3['Parcel_Billion']\n",
"\n",
"df3['S_T_P_A'] = df3['S_W_A'] + df3['S_L_P_A']\n",
"df3['S_T_P_L'] = df3['S_W_L'] + df3['S_L_P_L']\n",
"df3['S_T_P_H'] = df3['S_W_H'] + df3['S_L_P_H']\n",
"\n",
"#Limiting\n",
"csp = df3.loc[:,['SLR','Parcel_Billion','S_T_P_A', 'S_T_P_L', 'S_T_P_H',\n",
" 'S_W_A', 'S_W_L', 'S_W_H',\n",
" 'S_L_P_A','S_L_P_L','S_L_P_H','Leng_Total']]\n",
"\n",
"# exporting\n",
"csp.to_csv('data/no_storm/current_simple_parcel.csv')"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SLR | \n",
" Parcel_Billion | \n",
" S_T_P_A | \n",
" S_T_P_L | \n",
" S_T_P_H | \n",
" S_W_A | \n",
" S_W_L | \n",
" S_W_H | \n",
" S_L_P_A | \n",
" S_L_P_L | \n",
" S_L_P_H | \n",
" Leng_Total | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 0.911143 | \n",
" 7.989017 | \n",
" 5.062601 | \n",
" 10.915433 | \n",
" 3.927341 | \n",
" 2.576191 | \n",
" 5.278490 | \n",
" 4.061676 | \n",
" 2.486410 | \n",
" 5.636943 | \n",
" 300494.732280 | \n",
"
\n",
" \n",
" 1 | \n",
" 50 | \n",
" 1.341048 | \n",
" 13.311992 | \n",
" 8.470455 | \n",
" 18.153528 | \n",
" 7.334642 | \n",
" 4.811256 | \n",
" 9.858028 | \n",
" 5.977350 | \n",
" 3.659199 | \n",
" 8.295500 | \n",
" 394148.545024 | \n",
"
\n",
" \n",
" 2 | \n",
" 100 | \n",
" 2.333810 | \n",
" 17.557283 | \n",
" 11.518045 | \n",
" 23.596520 | \n",
" 10.082489 | \n",
" 6.613743 | \n",
" 13.551235 | \n",
" 7.474793 | \n",
" 4.904302 | \n",
" 10.045285 | \n",
" 449231.000352 | \n",
"
\n",
" \n",
" 3 | \n",
" 150 | \n",
" 2.333810 | \n",
" 38.205890 | \n",
" 24.344895 | \n",
" 52.066885 | \n",
" 26.128230 | \n",
" 17.139160 | \n",
" 35.117300 | \n",
" 12.077660 | \n",
" 7.205735 | \n",
" 16.949586 | \n",
" 716758.235094 | \n",
"
\n",
" \n",
" 4 | \n",
" 200 | \n",
" 2.188130 | \n",
" 52.534695 | \n",
" 33.316915 | \n",
" 71.752475 | \n",
" 38.185279 | \n",
" 25.048142 | \n",
" 51.322416 | \n",
" 14.349416 | \n",
" 8.268773 | \n",
" 20.430059 | \n",
" 790553.230836 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SLR Parcel_Billion S_T_P_A S_T_P_L S_T_P_H S_W_A S_W_L \\\n",
"0 0 0.911143 7.989017 5.062601 10.915433 3.927341 2.576191 \n",
"1 50 1.341048 13.311992 8.470455 18.153528 7.334642 4.811256 \n",
"2 100 2.333810 17.557283 11.518045 23.596520 10.082489 6.613743 \n",
"3 150 2.333810 38.205890 24.344895 52.066885 26.128230 17.139160 \n",
"4 200 2.188130 52.534695 33.316915 71.752475 38.185279 25.048142 \n",
"\n",
" S_W_H S_L_P_A S_L_P_L S_L_P_H Leng_Total \n",
"0 5.278490 4.061676 2.486410 5.636943 300494.732280 \n",
"1 9.858028 5.977350 3.659199 8.295500 394148.545024 \n",
"2 13.551235 7.474793 4.904302 10.045285 449231.000352 \n",
"3 35.117300 12.077660 7.205735 16.949586 716758.235094 \n",
"4 51.322416 14.349416 8.268773 20.430059 790553.230836 "
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"csp.head(n=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cost Approach 3 - Complex Landform Cost - No Parcel"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Setting Variables\n",
"wall_average = 218000\n",
"wall_low = 143000\n",
"wall_high = 293000\n",
"\n",
"levee_average = 8000\n",
"levee_low = 4000\n",
"levee_high = 12000\n",
"\n",
"fboard = 0.6096"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fresh - Approach 3 - Complex Landform Cost - No Parcel¶"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"# Import data\n",
"df = pd.read_csv('data/fresh_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\"\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"#breaking into landform and wall\n",
"df_w = df[df['LorW'] == \"Wall\"]\n",
"df_l = df[df['LorW'] == \"Landform\"]\n",
"\n",
"# creating the landform cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 3:\n",
" return 3\n",
" elif row [\"0_raise\"] > 1.5 and row[\"0_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 3:\n",
" return 3\n",
" elif row [\"50_raise\"] > 1.5 and row[\"50_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 3:\n",
" return 3\n",
" elif row [\"100_raise\"] > 1.5 and row[\"100_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 3:\n",
" return 3\n",
" elif row [\"150_raise\"] > 1.5 and row[\"150_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 3:\n",
" return 3\n",
" elif row [\"200_raise\"] > 1.5 and row[\"200_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 3:\n",
" return 3\n",
" elif row [\"500_raise\"] > 1.5 and row[\"500_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1 \n",
"\n",
"# applying the if statements above \n",
"df_l = df_l.assign(c_f_0slr=df_l.apply(set_cost_0slr, axis=1))\n",
"df_l = df_l.assign(c_f_50slr=df_l.apply(set_cost_50slr, axis=1))\n",
"df_l = df_l.assign(c_f_100slr=df_l.apply(set_cost_100slr, axis=1))\n",
"df_l = df_l.assign(c_f_150slr=df_l.apply(set_cost_150slr, axis=1))\n",
"df_l = df_l.assign(c_f_200slr=df_l.apply(set_cost_200slr, axis=1))\n",
"df_l = df_l.assign(c_f_500slr=df_l.apply(set_cost_500slr, axis=1))\n",
"\n",
"# creating the wall cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5 \n",
"\n",
"# applying the if statements above \n",
"df_w = df_w.assign(c_f_0slr=df_w.apply(set_cost_0slr, axis=1))\n",
"df_w = df_w.assign(c_f_50slr=df_w.apply(set_cost_50slr, axis=1))\n",
"df_w = df_w.assign(c_f_100slr=df_w.apply(set_cost_100slr, axis=1))\n",
"df_w = df_w.assign(c_f_150slr=df_w.apply(set_cost_150slr, axis=1))\n",
"df_w = df_w.assign(c_f_200slr=df_w.apply(set_cost_200slr, axis=1))\n",
"df_w = df_w.assign(c_f_500slr=df_w.apply(set_cost_500slr, axis=1))\n",
"\n",
"# reconnecting wall and landform data\n",
"df = df_w.append(df_l)\n",
"\n",
"# doing the key math average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_500slr']\n",
"\n",
"# doing the key math low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_500slr']\n",
"\n",
"# doing the key math high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_500slr']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"fresh_complex = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"fresh_complex = fresh_complex.rename(columns = {\n",
" 'High_Billion':'C_T_H',\n",
" 'High_L_Billion':'C_L_H',\n",
" 'High_W_Billion':'C_W_H',\n",
" 'Low_Billion':'C_T_L',\n",
" 'Low_L_Billion':'C_L_L',\n",
" 'Low_W_Billion':'C_W_L',\n",
" 'Average_Billion': 'C_T_A',\n",
" 'Average_L_Billion': 'C_L_A',\n",
" 'Average_W_Billion': 'C_W_A', })\n",
"\n",
"fresh_complex.to_csv('data/no_storm/fresh_complex.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Salt - Approach 3 - Complex Landform Cost - No Parcel¶"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"# Import data\n",
"df = pd.read_csv('data/salt_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\"\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"#breaking into landform and wall\n",
"df_w = df[df['LorW'] == \"Wall\"]\n",
"df_l = df[df['LorW'] == \"Landform\"]\n",
"\n",
"# creating the landform cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 3:\n",
" return 3\n",
" elif row [\"0_raise\"] > 1.5 and row[\"0_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 3:\n",
" return 3\n",
" elif row [\"50_raise\"] > 1.5 and row[\"50_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 3:\n",
" return 3\n",
" elif row [\"100_raise\"] > 1.5 and row[\"100_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 3:\n",
" return 3\n",
" elif row [\"150_raise\"] > 1.5 and row[\"150_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 3:\n",
" return 3\n",
" elif row [\"200_raise\"] > 1.5 and row[\"200_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 3:\n",
" return 3\n",
" elif row [\"500_raise\"] > 1.5 and row[\"500_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1 \n",
"\n",
"# applying the if statements above \n",
"df_l = df_l.assign(c_f_0slr=df_l.apply(set_cost_0slr, axis=1))\n",
"df_l = df_l.assign(c_f_50slr=df_l.apply(set_cost_50slr, axis=1))\n",
"df_l = df_l.assign(c_f_100slr=df_l.apply(set_cost_100slr, axis=1))\n",
"df_l = df_l.assign(c_f_150slr=df_l.apply(set_cost_150slr, axis=1))\n",
"df_l = df_l.assign(c_f_200slr=df_l.apply(set_cost_200slr, axis=1))\n",
"df_l = df_l.assign(c_f_500slr=df_l.apply(set_cost_500slr, axis=1))\n",
"\n",
"# creating the wall cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5 \n",
"\n",
"# applying the if statements above \n",
"df_w = df_w.assign(c_f_0slr=df_w.apply(set_cost_0slr, axis=1))\n",
"df_w = df_w.assign(c_f_50slr=df_w.apply(set_cost_50slr, axis=1))\n",
"df_w = df_w.assign(c_f_100slr=df_w.apply(set_cost_100slr, axis=1))\n",
"df_w = df_w.assign(c_f_150slr=df_w.apply(set_cost_150slr, axis=1))\n",
"df_w = df_w.assign(c_f_200slr=df_w.apply(set_cost_200slr, axis=1))\n",
"df_w = df_w.assign(c_f_500slr=df_w.apply(set_cost_500slr, axis=1))\n",
"\n",
"# reconnecting wall and landform data\n",
"df = df_w.append(df_l)\n",
"\n",
"# doing the key math average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_500slr']\n",
"\n",
"# doing the key math low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_500slr']\n",
"\n",
"# doing the key math high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_500slr']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"salt_complex = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"salt_complex = salt_complex.rename(columns = {\n",
" 'High_Billion':'C_T_H',\n",
" 'High_L_Billion':'C_L_H',\n",
" 'High_W_Billion':'C_W_H',\n",
" 'Low_Billion':'C_T_L',\n",
" 'Low_L_Billion':'C_L_L',\n",
" 'Low_W_Billion':'C_W_L',\n",
" 'Average_Billion': 'C_T_A',\n",
" 'Average_L_Billion': 'C_L_A',\n",
" 'Average_W_Billion': 'C_W_A', })\n",
"\n",
"salt_complex.to_csv('data/no_storm/salt_complex.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Current - Approach 3 - Complex Landform Cost - No Parcel¶"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/daniellahirschfeld/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" interactivity=interactivity, compiler=compiler, result=result)\n"
]
}
],
"source": [
"# Import data\n",
"df = pd.read_csv('data/current_full_fix.csv')\n",
"\n",
"# these costs are based on the average of a number of studies and plus / minus a standard deviation\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Ave'] = wall_average\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Ave'] = levee_average\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_High'] = wall_high\n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_High'] = levee_high\n",
"\n",
"df.ix[(df.LorW == 'Wall') ,'Cost_Example_Low'] = wall_low \n",
"df.ix[(df.LorW == 'Landform') ,'Cost_Example_Low'] = levee_low\n",
"\n",
"# create an overtop with \"freeboard\"\n",
"df.loc[df.o_000_000 > 0,'0_raise'] = df['o_000_000'] + fboard\n",
"df.loc[df.o_050_000 > 0,'50_raise'] = df['o_050_000'] + fboard\n",
"df.loc[df.o_100_000 > 0,'100_raise'] = df['o_100_000'] + fboard\n",
"df.loc[df.o_150_000 > 0,'150_raise'] = df['o_150_000'] + fboard\n",
"df.loc[df.o_200_000 > 0,'200_raise'] = df['o_200_000'] + fboard\n",
"df.loc[df.o_500_000 > 0,'500_raise'] = df['o_500_000'] + fboard\n",
"\n",
"#breaking into landform and wall\n",
"df_w = df[df['LorW'] == \"Wall\"]\n",
"df_l = df[df['LorW'] == \"Landform\"]\n",
"\n",
"# creating the landform cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 3:\n",
" return 3\n",
" elif row [\"0_raise\"] > 1.5 and row[\"0_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 3:\n",
" return 3\n",
" elif row [\"50_raise\"] > 1.5 and row[\"50_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 3:\n",
" return 3\n",
" elif row [\"100_raise\"] > 1.5 and row[\"100_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 3:\n",
" return 3\n",
" elif row [\"150_raise\"] > 1.5 and row[\"150_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 3:\n",
" return 3\n",
" elif row [\"200_raise\"] > 1.5 and row[\"200_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 3:\n",
" return 3\n",
" elif row [\"500_raise\"] > 1.5 and row[\"500_raise\"] < 3:\n",
" return 2\n",
" else: \n",
" return 1 \n",
"\n",
"# applying the if statements above \n",
"df_l = df_l.assign(c_f_0slr=df_l.apply(set_cost_0slr, axis=1))\n",
"df_l = df_l.assign(c_f_50slr=df_l.apply(set_cost_50slr, axis=1))\n",
"df_l = df_l.assign(c_f_100slr=df_l.apply(set_cost_100slr, axis=1))\n",
"df_l = df_l.assign(c_f_150slr=df_l.apply(set_cost_150slr, axis=1))\n",
"df_l = df_l.assign(c_f_200slr=df_l.apply(set_cost_200slr, axis=1))\n",
"df_l = df_l.assign(c_f_500slr=df_l.apply(set_cost_500slr, axis=1))\n",
"\n",
"# creating the wall cost factor\n",
"\n",
"#creating if statement 0 slr\n",
"def set_cost_0slr(row):\n",
" if row[\"0_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 50 slr\n",
"def set_cost_50slr(row):\n",
" if row[\"50_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 100 slr\n",
"def set_cost_100slr(row):\n",
" if row[\"100_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 150 slr\n",
"def set_cost_150slr(row):\n",
" if row[\"150_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 200 slr\n",
"def set_cost_200slr(row):\n",
" if row[\"200_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5\n",
"\n",
"#creating if statement 500 slr\n",
"def set_cost_500slr(row):\n",
" if row[\"500_raise\"] > 0.5:\n",
" return 4\n",
" else: \n",
" return 0.5 \n",
"\n",
"# applying the if statements above \n",
"df_w = df_w.assign(c_f_0slr=df_w.apply(set_cost_0slr, axis=1))\n",
"df_w = df_w.assign(c_f_50slr=df_w.apply(set_cost_50slr, axis=1))\n",
"df_w = df_w.assign(c_f_100slr=df_w.apply(set_cost_100slr, axis=1))\n",
"df_w = df_w.assign(c_f_150slr=df_w.apply(set_cost_150slr, axis=1))\n",
"df_w = df_w.assign(c_f_200slr=df_w.apply(set_cost_200slr, axis=1))\n",
"df_w = df_w.assign(c_f_500slr=df_w.apply(set_cost_500slr, axis=1))\n",
"\n",
"# reconnecting wall and landform data\n",
"df = df_w.append(df_l)\n",
"\n",
"# doing the key math average\n",
"df.loc[df.o_000_000 > 0,'0_cost_a'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_a'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_a'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_a'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_a'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_a'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Ave'] * df['c_f_500slr']\n",
"\n",
"# doing the key math low\n",
"df.loc[df.o_000_000 > 0,'0_cost_l'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_l'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_l'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_l'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_l'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_l'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_Low'] * df['c_f_500slr']\n",
"\n",
"# doing the key math high\n",
"df.loc[df.o_000_000 > 0,'0_cost_h'] = df['0_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_0slr']\n",
"df.loc[df.o_050_000 > 0,'50_cost_h'] = df['50_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_50slr']\n",
"df.loc[df.o_100_000 > 0,'100_cost_h'] = df['100_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_100slr']\n",
"df.loc[df.o_150_000 > 0,'150_cost_h'] = df['150_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_150slr']\n",
"df.loc[df.o_200_000 > 0,'200_cost_h'] = df['200_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_200slr']\n",
"df.loc[df.o_500_000 > 0,'500_cost_h'] = df['500_raise'] * df['LengthUpd'] * df['Cost_Example_High'] * df['c_f_500slr']\n",
"\n",
"#getting length for each\n",
"df.loc[df.o_000_000 > 0,'0_length'] = df['LengthUpd']\n",
"df.loc[df.o_050_000 > 0,'50_length'] = df['LengthUpd']\n",
"df.loc[df.o_100_000 > 0,'100_length'] = df['LengthUpd']\n",
"df.loc[df.o_150_000 > 0,'150_length'] = df['LengthUpd']\n",
"df.loc[df.o_200_000 > 0,'200_length'] = df['LengthUpd']\n",
"df.loc[df.o_500_000 > 0,'500_length'] = df['LengthUpd']\n",
"\n",
"# making df for average, low and high and length\n",
"df_a = df.loc[:,['LorW','0_cost_a','50_cost_a','100_cost_a','150_cost_a','200_cost_a', '500_cost_a']]\n",
"\n",
"df_l = df.loc[:,['LorW','0_cost_l','50_cost_l','100_cost_l','150_cost_l','200_cost_l','500_cost_l']]\n",
"\n",
"df_h = df.loc[:,['LorW','0_cost_h','50_cost_h','100_cost_h','150_cost_h','200_cost_h','500_cost_h']]\n",
"\n",
"df_leng = df.loc[:,['LorW','0_length','50_length','100_length','150_length','200_length','500_length']]\n",
"\n",
"\n",
"# get land / wall values\n",
"df_a = df_a.groupby([\"LorW\"], as_index=False).sum()\n",
"df_h = df_h.groupby([\"LorW\"], as_index=False).sum()\n",
"df_l = df_l.groupby([\"LorW\"], as_index=False).sum()\n",
"df_leng = df_leng.groupby([\"LorW\"], as_index=False).sum()\n",
"\n",
"\n",
"# adding the index\n",
"df_a2 = df_a.set_index('LorW')\n",
"df_h2 = df_h.set_index('LorW')\n",
"df_l2 = df_l.set_index('LorW')\n",
"df_leng2 = df_leng.set_index('LorW')\n",
"\n",
"# transposing\n",
"df_a = df_a2.T\n",
"df_h = df_h2.T\n",
"df_l = df_l2.T\n",
"df_leng = df_leng2.T\n",
"\n",
"#recalculating Average\n",
"df_a['Average_Total'] = df_a['Landform'] + df_a['Wall']\n",
"df_a['Average_Billion'] = df_a['Average_Total'] / 1000000000\n",
"df_a['Average_L_Billion'] = df_a['Landform'] / 1000000000\n",
"df_a['Average_W_Billion'] = df_a['Wall'] / 1000000000\n",
"\n",
"#recalculating High\n",
"df_h['High_Total'] = df_h['Landform'] + df_h['Wall']\n",
"df_h['High_Billion'] = df_h['High_Total'] / 1000000000\n",
"df_h['High_L_Billion'] = df_h['Landform'] / 1000000000\n",
"df_h['High_W_Billion'] = df_h['Wall'] / 1000000000\n",
"\n",
"#recalculating Low\n",
"df_l['Low_Total'] = df_l['Landform'] + df_l['Wall']\n",
"df_l['Low_Billion'] = df_l['Low_Total'] / 1000000000\n",
"df_l['Low_L_Billion'] = df_l['Landform'] / 1000000000\n",
"df_l['Low_W_Billion'] = df_l['Wall'] / 1000000000\n",
"\n",
"#recalculating Length\n",
"df_leng['Leng_Total'] = df_leng['Landform'] + df_leng['Wall']\n",
"\n",
"# restting index\n",
"df_a.reset_index(level=0, inplace=True)\n",
"df_h.reset_index(level=0, inplace=True)\n",
"df_l.reset_index(level=0, inplace=True)\n",
"df_leng.reset_index(level=0, inplace=True)\n",
"\n",
"\n",
"#adding slr\n",
"dic = {'0_cost_a': 0, '50_cost_a': 50, '100_cost_a': 100, '150_cost_a': 150,'200_cost_a': 200, '500_cost_a': 500}\n",
"df_a['SLR'] = df_a['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_l': 0, '50_cost_l': 50, '100_cost_l': 100, '150_cost_l': 150, '200_cost_l': 200, '500_cost_l': 500}\n",
"df_l['SLR'] = df_l['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_cost_h': 0, '50_cost_h': 50,'100_cost_h': 100, '150_cost_h': 150, '200_cost_h': 200, '500_cost_h': 500}\n",
"df_h['SLR'] = df_h['index'].apply(lambda x: dic[x])\n",
"\n",
"dic = {'0_length': 0, '50_length': 50, '100_length': 100, '150_length': 150, '200_length': 200, '500_length': 500}\n",
"df_leng['SLR'] = df_leng['index'].apply(lambda x: dic[x])\n",
"\n",
"#removing extra columns\n",
"df_h = df_h.loc[:,['SLR','High_Billion','High_L_Billion','High_W_Billion']]\n",
"df_l = df_l.loc[:,['SLR','Low_Billion','Low_L_Billion','Low_W_Billion']]\n",
"df_a = df_a.loc[:,['SLR','Average_Billion','Average_L_Billion','Average_W_Billion']]\n",
"df_leng = df_leng.loc[:,['SLR','Leng_Total']]\n",
"\n",
"\n",
"c1 = pd.merge(df_a, df_l, left_on='SLR', right_on='SLR')\n",
"c2 = pd.merge(c1, df_leng, left_on='SLR', right_on='SLR')\n",
"current_complex = pd.merge(c2, df_h, left_on='SLR', right_on='SLR')\n",
"\n",
"current_complex = current_complex.rename(columns = {\n",
" 'High_Billion':'C_T_H',\n",
" 'High_L_Billion':'C_L_H',\n",
" 'High_W_Billion':'C_W_H',\n",
" 'Low_Billion':'C_T_L',\n",
" 'Low_L_Billion':'C_L_L',\n",
" 'Low_W_Billion':'C_W_L',\n",
" 'Average_Billion': 'C_T_A',\n",
" 'Average_L_Billion': 'C_L_A',\n",
" 'Average_W_Billion': 'C_W_A', })\n",
"\n",
"current_complex.to_csv('data/no_storm/current_complex.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cost Approach 4 - Complex Landform Cost and Parcel"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Fresh - Approach 4 - Complex Landform Cost and Parcel"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#narrowing\n",
"fsp = fsp.loc[:,['SLR','Parcel_Billion']]\n",
"\n",
"# merging complex and parcel\n",
"df = pd.merge(fresh_complex, fsp, left_on='SLR', right_on='SLR')\n",
"\n",
"# recalculating \n",
"df['C_L_P_A'] = df['C_L_A'] + df['Parcel_Billion']\n",
"df['C_L_P_L'] = df['C_L_L'] + df['Parcel_Billion']\n",
"df['C_L_P_H'] = df['C_L_H'] + df['Parcel_Billion']\n",
"\n",
"df['C_T_P_A'] = df['C_L_P_A'] + df['C_W_A']\n",
"df['C_T_P_L'] = df['C_L_P_L'] + df['C_W_L']\n",
"df['C_T_P_H'] = df['C_L_P_H'] + df['C_W_H']\n",
"\n",
"#narrowing\n",
"fcp = df.loc[:,['SLR','Parcel_Billion','C_W_A', 'C_W_H', 'C_W_L',\n",
" 'Leng_Total', 'Parcel_Billion',\n",
" 'C_L_P_A', 'C_L_P_L', 'C_L_P_H',\n",
" 'C_T_P_A', 'C_T_P_L', 'C_T_P_H']]\n",
"#exporting\n",
"fcp.to_csv('data/no_storm/fresh_complex_parcels.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Salt - Approach 4 - Complex Landform Cost and Parcel"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#narrowing\n",
"ssp = ssp.loc[:,['SLR','Parcel_Billion']]\n",
"\n",
"# merging complex and parcel\n",
"df = pd.merge(salt_complex, ssp, left_on='SLR', right_on='SLR')\n",
"\n",
"# recalculating \n",
"df['C_L_P_A'] = df['C_L_A'] + df['Parcel_Billion']\n",
"df['C_L_P_L'] = df['C_L_L'] + df['Parcel_Billion']\n",
"df['C_L_P_H'] = df['C_L_H'] + df['Parcel_Billion']\n",
"\n",
"df['C_T_P_A'] = df['C_L_P_A'] + df['C_W_A']\n",
"df['C_T_P_L'] = df['C_L_P_L'] + df['C_W_L']\n",
"df['C_T_P_H'] = df['C_L_P_H'] + df['C_W_H']\n",
"\n",
"#narrowing\n",
"scp = df.loc[:,['SLR','Parcel_Billion','C_W_A', 'C_W_H', 'C_W_L',\n",
" 'Leng_Total', 'Parcel_Billion',\n",
" 'C_L_P_A', 'C_L_P_L', 'C_L_P_H',\n",
" 'C_T_P_A', 'C_T_P_L', 'C_T_P_H']]\n",
"#exporting\n",
"scp.to_csv('data/no_storm/salt_complex_parcels.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Current - Approach 4 - Complex Landform Cost and Parcel"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#narrowing\n",
"csp = csp.loc[:,['SLR','Parcel_Billion']]\n",
"\n",
"# merging complex and parcel\n",
"df = pd.merge(current_complex, csp, left_on='SLR', right_on='SLR')\n",
"\n",
"# recalculating \n",
"df['C_L_P_A'] = df['C_L_A'] + df['Parcel_Billion']\n",
"df['C_L_P_L'] = df['C_L_L'] + df['Parcel_Billion']\n",
"df['C_L_P_H'] = df['C_L_H'] + df['Parcel_Billion']\n",
"\n",
"df['C_T_P_A'] = df['C_L_P_A'] + df['C_W_A']\n",
"df['C_T_P_L'] = df['C_L_P_L'] + df['C_W_L']\n",
"df['C_T_P_H'] = df['C_L_P_H'] + df['C_W_H']\n",
"\n",
"#narrowing\n",
"ccp = df.loc[:,['SLR','Parcel_Billion','C_W_A', 'C_W_H', 'C_W_L',\n",
" 'Leng_Total', 'Parcel_Billion',\n",
" 'C_L_P_A', 'C_L_P_L', 'C_L_P_H',\n",
" 'C_T_P_A', 'C_T_P_L', 'C_T_P_H']]\n",
"#exporting\n",
"ccp.to_csv('data/no_storm/current_complex_parcels.csv')"
]
},
{
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}