From 9ebe3b02373ee34c0f1eac961e01faa72a74b9e1 Mon Sep 17 00:00:00 2001
From: richik-ray <45549622+richik-ray@users.noreply.github.com>
Date: Sun, 3 Nov 2019 10:52:52 -0500
Subject: [PATCH] final dataframe
---
final stacking.ipynb | 490 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 490 insertions(+)
create mode 100644 final stacking.ipynb
diff --git a/final stacking.ipynb b/final stacking.ipynb
new file mode 100644
index 0000000..7198bf5
--- /dev/null
+++ b/final stacking.ipynb
@@ -0,0 +1,490 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "import pandas as pd\n",
+ "pd.set_option('display.max_columns', None)\n",
+ "pd.set_option('display.max_colwidth', -1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 107,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Value | \n",
+ " County, State | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 184500.0 | \n",
+ " Valdez Cordova, AK | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 397000.0 | \n",
+ " Sitka, AK | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 276450.0 | \n",
+ " Matanuska Susitna, AK | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 289000.0 | \n",
+ " Ketchikan Gateway, AK | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 318000.0 | \n",
+ " Anchorage, AK | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 337000.0 | \n",
+ " Kodiak Island, AK | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 384900.0 | \n",
+ " Juneau, AK | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 229900.0 | \n",
+ " Fairbanks North Star, AK | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " 259000.0 | \n",
+ " Kenai Peninsula, AK | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " 159000.0 | \n",
+ " Clarke, AL | \n",
+ "
\n",
+ " \n",
+ " 10 | \n",
+ " 188700.0 | \n",
+ " Bibb, AL | \n",
+ "
\n",
+ " \n",
+ " 11 | \n",
+ " 173000.0 | \n",
+ " Coffee, AL | \n",
+ "
\n",
+ " \n",
+ " 12 | \n",
+ " 147000.0 | \n",
+ " Covington, AL | \n",
+ "
\n",
+ " \n",
+ " 13 | \n",
+ " 170000.0 | \n",
+ " De Kalb, AL | \n",
+ "
\n",
+ " \n",
+ " 14 | \n",
+ " 134900.0 | \n",
+ " Escambia, AL | \n",
+ "
\n",
+ " \n",
+ " 15 | \n",
+ " 117684.0 | \n",
+ " Monroe, AL | \n",
+ "
\n",
+ " \n",
+ " 16 | \n",
+ " 310000.0 | \n",
+ " Baldwin, AL | \n",
+ "
\n",
+ " \n",
+ " 17 | \n",
+ " 169500.0 | \n",
+ " Barbour, AL | \n",
+ "
\n",
+ " \n",
+ " 18 | \n",
+ " 152950.0 | \n",
+ " Walker, AL | \n",
+ "
\n",
+ " \n",
+ " 19 | \n",
+ " 149900.0 | \n",
+ " Hale, AL | \n",
+ "
\n",
+ " \n",
+ " 20 | \n",
+ " 299949.5 | \n",
+ " Tallapoosa, AL | \n",
+ "
\n",
+ " \n",
+ " 21 | \n",
+ " 299900.0 | \n",
+ " Winston, AL | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ " 183999.0 | \n",
+ " Montgomery, AL | \n",
+ "
\n",
+ " \n",
+ " 23 | \n",
+ " 170450.0 | \n",
+ " Chilton, AL | \n",
+ "
\n",
+ " \n",
+ " 24 | \n",
+ " 185000.0 | \n",
+ " Blount, AL | \n",
+ "
\n",
+ " \n",
+ " 25 | \n",
+ " 137500.0 | \n",
+ " Crenshaw, AL | \n",
+ "
\n",
+ " \n",
+ " 26 | \n",
+ " 139900.0 | \n",
+ " Russell, AL | \n",
+ "
\n",
+ " \n",
+ " 27 | \n",
+ " 99000.0 | \n",
+ " Dallas, AL | \n",
+ "
\n",
+ " \n",
+ " 28 | \n",
+ " 175000.0 | \n",
+ " Jackson, AL | \n",
+ "
\n",
+ " \n",
+ " 29 | \n",
+ " 219000.0 | \n",
+ " Cherokee, AL | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 2259 | \n",
+ " 139900.0 | \n",
+ " Kanawha, WV | \n",
+ "
\n",
+ " \n",
+ " 2260 | \n",
+ " 133950.0 | \n",
+ " Pendleton, WV | \n",
+ "
\n",
+ " \n",
+ " 2261 | \n",
+ " 94500.0 | \n",
+ " Hancock, WV | \n",
+ "
\n",
+ " \n",
+ " 2262 | \n",
+ " 151950.0 | \n",
+ " Hardy, WV | \n",
+ "
\n",
+ " \n",
+ " 2263 | \n",
+ " 160500.0 | \n",
+ " Preston, WV | \n",
+ "
\n",
+ " \n",
+ " 2264 | \n",
+ " 199000.0 | \n",
+ " Hampshire, WV | \n",
+ "
\n",
+ " \n",
+ " 2265 | \n",
+ " 135500.0 | \n",
+ " Nicholas, WV | \n",
+ "
\n",
+ " \n",
+ " 2266 | \n",
+ " 298500.0 | \n",
+ " Jefferson, WV | \n",
+ "
\n",
+ " \n",
+ " 2267 | \n",
+ " 159000.0 | \n",
+ " Upshur, WV | \n",
+ "
\n",
+ " \n",
+ " 2268 | \n",
+ " 199900.0 | \n",
+ " Uinta, WY | \n",
+ "
\n",
+ " \n",
+ " 2269 | \n",
+ " 260000.0 | \n",
+ " Sublette, WY | \n",
+ "
\n",
+ " \n",
+ " 2270 | \n",
+ " 269900.0 | \n",
+ " Crook, WY | \n",
+ "
\n",
+ " \n",
+ " 2271 | \n",
+ " 175900.0 | \n",
+ " Carbon, WY | \n",
+ "
\n",
+ " \n",
+ " 2272 | \n",
+ " 360000.0 | \n",
+ " Lincoln, WY | \n",
+ "
\n",
+ " \n",
+ " 2273 | \n",
+ " 225450.0 | \n",
+ " Fremont, WY | \n",
+ "
\n",
+ " \n",
+ " 2274 | \n",
+ " 182450.0 | \n",
+ " Weston, WY | \n",
+ "
\n",
+ " \n",
+ " 2275 | \n",
+ " 154900.0 | \n",
+ " Washakie, WY | \n",
+ "
\n",
+ " \n",
+ " 2276 | \n",
+ " 161750.0 | \n",
+ " Goshen, WY | \n",
+ "
\n",
+ " \n",
+ " 2277 | \n",
+ " 216900.0 | \n",
+ " Natrona, WY | \n",
+ "
\n",
+ " \n",
+ " 2278 | \n",
+ " 248000.0 | \n",
+ " Johnson, WY | \n",
+ "
\n",
+ " \n",
+ " 2279 | \n",
+ " 235000.0 | \n",
+ " Sweetwater, WY | \n",
+ "
\n",
+ " \n",
+ " 2280 | \n",
+ " 350000.0 | \n",
+ " Park, WY | \n",
+ "
\n",
+ " \n",
+ " 2281 | \n",
+ " 1662500.0 | \n",
+ " Teton, WY | \n",
+ "
\n",
+ " \n",
+ " 2282 | \n",
+ " 229925.0 | \n",
+ " Converse, WY | \n",
+ "
\n",
+ " \n",
+ " 2283 | \n",
+ " 265000.0 | \n",
+ " Albany, WY | \n",
+ "
\n",
+ " \n",
+ " 2284 | \n",
+ " 229000.0 | \n",
+ " Campbell, WY | \n",
+ "
\n",
+ " \n",
+ " 2285 | \n",
+ " 190000.0 | \n",
+ " Platte, WY | \n",
+ "
\n",
+ " \n",
+ " 2286 | \n",
+ " 161250.0 | \n",
+ " Hot Springs, WY | \n",
+ "
\n",
+ " \n",
+ " 2287 | \n",
+ " 275000.0 | \n",
+ " Sheridan, WY | \n",
+ "
\n",
+ " \n",
+ " 2288 | \n",
+ " 296450.0 | \n",
+ " Laramie, WY | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
2289 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Value County, State\n",
+ "0 184500.0 Valdez Cordova, AK \n",
+ "1 397000.0 Sitka, AK \n",
+ "2 276450.0 Matanuska Susitna, AK \n",
+ "3 289000.0 Ketchikan Gateway, AK \n",
+ "4 318000.0 Anchorage, AK \n",
+ "5 337000.0 Kodiak Island, AK \n",
+ "6 384900.0 Juneau, AK \n",
+ "7 229900.0 Fairbanks North Star, AK\n",
+ "8 259000.0 Kenai Peninsula, AK \n",
+ "9 159000.0 Clarke, AL \n",
+ "10 188700.0 Bibb, AL \n",
+ "11 173000.0 Coffee, AL \n",
+ "12 147000.0 Covington, AL \n",
+ "13 170000.0 De Kalb, AL \n",
+ "14 134900.0 Escambia, AL \n",
+ "15 117684.0 Monroe, AL \n",
+ "16 310000.0 Baldwin, AL \n",
+ "17 169500.0 Barbour, AL \n",
+ "18 152950.0 Walker, AL \n",
+ "19 149900.0 Hale, AL \n",
+ "20 299949.5 Tallapoosa, AL \n",
+ "21 299900.0 Winston, AL \n",
+ "22 183999.0 Montgomery, AL \n",
+ "23 170450.0 Chilton, AL \n",
+ "24 185000.0 Blount, AL \n",
+ "25 137500.0 Crenshaw, AL \n",
+ "26 139900.0 Russell, AL \n",
+ "27 99000.0 Dallas, AL \n",
+ "28 175000.0 Jackson, AL \n",
+ "29 219000.0 Cherokee, AL \n",
+ "... ... ... \n",
+ "2259 139900.0 Kanawha, WV \n",
+ "2260 133950.0 Pendleton, WV \n",
+ "2261 94500.0 Hancock, WV \n",
+ "2262 151950.0 Hardy, WV \n",
+ "2263 160500.0 Preston, WV \n",
+ "2264 199000.0 Hampshire, WV \n",
+ "2265 135500.0 Nicholas, WV \n",
+ "2266 298500.0 Jefferson, WV \n",
+ "2267 159000.0 Upshur, WV \n",
+ "2268 199900.0 Uinta, WY \n",
+ "2269 260000.0 Sublette, WY \n",
+ "2270 269900.0 Crook, WY \n",
+ "2271 175900.0 Carbon, WY \n",
+ "2272 360000.0 Lincoln, WY \n",
+ "2273 225450.0 Fremont, WY \n",
+ "2274 182450.0 Weston, WY \n",
+ "2275 154900.0 Washakie, WY \n",
+ "2276 161750.0 Goshen, WY \n",
+ "2277 216900.0 Natrona, WY \n",
+ "2278 248000.0 Johnson, WY \n",
+ "2279 235000.0 Sweetwater, WY \n",
+ "2280 350000.0 Park, WY \n",
+ "2281 1662500.0 Teton, WY \n",
+ "2282 229925.0 Converse, WY \n",
+ "2283 265000.0 Albany, WY \n",
+ "2284 229000.0 Campbell, WY \n",
+ "2285 190000.0 Platte, WY \n",
+ "2286 161250.0 Hot Springs, WY \n",
+ "2287 275000.0 Sheridan, WY \n",
+ "2288 296450.0 Laramie, WY \n",
+ "\n",
+ "[2289 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 107,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "os.chdir(r\"C:\\Users\\rayri\\Desktop\\Python\\HackDuke\")\n",
+ "df = pd.read_csv(\"Housing Parsing.csv\")\n",
+ "#df[\"COUNTY\"] = df[\"COUNTY\"].str.replace(\"County\", \"\")\n",
+ "#df[\"COUNTY\"] = df[\"COUNTY\"].str.replace(\"Parish\", \"\")\n",
+ "#df[\"COUNTY\"] = df[\"COUNTY\"].str.replace(\"Borough\", \"\")\n",
+ "#df = df.sort_values(\"State\")\n",
+ "#df[\"State\"] = df[\"county_name\"].str[-2:]\n",
+ "#df[\"1901-2000\"] = df[\"1901-2000\"].str[:-2]\n",
+ "#df[\"COUNTY\"] = df[\"COUNTY\"].str[:-4]\n",
+ "#df[\"Value\"] = df[\"Value\"].str[:-2]\n",
+ "df = df.rename(columns = {\"RegionName\": \"County\"})\n",
+ "df = df.rename(columns = {\"2019-09\": \"Value\"})\n",
+ "#df = df.rename(columns = {\"perc\": \"Value\"})\n",
+ "#df[\"County\"] =df[\"County\"].str.title()\n",
+ "#df = df.drop(columns = [\"cohort\", \"zsc\"])\n",
+ "df['County'] = df['County'].str.strip()\n",
+ "df.drop(df.columns.difference(['County','State', 'Value']), 1, inplace=True)\n",
+ "df[\"County, State\"] = df[\"County\"] + \", \" + df[\"State\"]\n",
+ "df = df.drop(columns = [\"County\", \"State\"])\n",
+ "#df = df.drop(df.index[0])\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 108,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.to_csv(\"Housing Parsing2.csv\", index = False)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "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.7.3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}