|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 2, |
| 6 | + "id": "resistant-papua", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import pandas as pd" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": 38, |
| 16 | + "id": "fifty-poison", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "dataset = \"../Data/USA_Housing.csv\"\n", |
| 21 | + "df = pd.read_csv(dataset, header= 0)" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": 39, |
| 27 | + "id": "imported-campus", |
| 28 | + "metadata": {}, |
| 29 | + "outputs": [ |
| 30 | + { |
| 31 | + "data": { |
| 32 | + "text/plain": [ |
| 33 | + "Index(['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms',\n", |
| 34 | + " 'Avg. Area Number of Bedrooms', 'Area Population', 'Price', 'Address'],\n", |
| 35 | + " dtype='object')" |
| 36 | + ] |
| 37 | + }, |
| 38 | + "execution_count": 39, |
| 39 | + "metadata": {}, |
| 40 | + "output_type": "execute_result" |
| 41 | + } |
| 42 | + ], |
| 43 | + "source": [ |
| 44 | + "df.columns" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": 40, |
| 50 | + "id": "young-austin", |
| 51 | + "metadata": {}, |
| 52 | + "outputs": [ |
| 53 | + { |
| 54 | + "data": { |
| 55 | + "text/plain": [ |
| 56 | + "RangeIndex(start=0, stop=5000, step=1)" |
| 57 | + ] |
| 58 | + }, |
| 59 | + "execution_count": 40, |
| 60 | + "metadata": {}, |
| 61 | + "output_type": "execute_result" |
| 62 | + } |
| 63 | + ], |
| 64 | + "source": [ |
| 65 | + "df.index" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": 10, |
| 71 | + "id": "burning-indonesian", |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "df.set_index('Address',inplace=True)" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": 25, |
| 81 | + "id": "raising-fabric", |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [ |
| 84 | + { |
| 85 | + "data": { |
| 86 | + "text/html": [ |
| 87 | + "<div>\n", |
| 88 | + "<style scoped>\n", |
| 89 | + " .dataframe tbody tr th:only-of-type {\n", |
| 90 | + " vertical-align: middle;\n", |
| 91 | + " }\n", |
| 92 | + "\n", |
| 93 | + " .dataframe tbody tr th {\n", |
| 94 | + " vertical-align: top;\n", |
| 95 | + " }\n", |
| 96 | + "\n", |
| 97 | + " .dataframe thead th {\n", |
| 98 | + " text-align: right;\n", |
| 99 | + " }\n", |
| 100 | + "</style>\n", |
| 101 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 102 | + " <thead>\n", |
| 103 | + " <tr style=\"text-align: right;\">\n", |
| 104 | + " <th></th>\n", |
| 105 | + " <th>Avg. Area Income</th>\n", |
| 106 | + " <th>Avg. Area House Age</th>\n", |
| 107 | + " <th>Avg. Area Number of Rooms</th>\n", |
| 108 | + " </tr>\n", |
| 109 | + " <tr>\n", |
| 110 | + " <th>Address</th>\n", |
| 111 | + " <th></th>\n", |
| 112 | + " <th></th>\n", |
| 113 | + " <th></th>\n", |
| 114 | + " </tr>\n", |
| 115 | + " </thead>\n", |
| 116 | + " <tbody>\n", |
| 117 | + " <tr>\n", |
| 118 | + " <th>208 Michael Ferry Apt. 674\\r\\nLaurabury, NE 37010-5101</th>\n", |
| 119 | + " <td>79545.458574</td>\n", |
| 120 | + " <td>5.682861</td>\n", |
| 121 | + " <td>7.009188</td>\n", |
| 122 | + " </tr>\n", |
| 123 | + " <tr>\n", |
| 124 | + " <th>188 Johnson Views Suite 079\\r\\nLake Kathleen, CA 48958</th>\n", |
| 125 | + " <td>79248.642455</td>\n", |
| 126 | + " <td>6.002900</td>\n", |
| 127 | + " <td>6.730821</td>\n", |
| 128 | + " </tr>\n", |
| 129 | + " <tr>\n", |
| 130 | + " <th>9127 Elizabeth Stravenue\\r\\nDanieltown, WI 06482-3489</th>\n", |
| 131 | + " <td>61287.067179</td>\n", |
| 132 | + " <td>5.865890</td>\n", |
| 133 | + " <td>8.512727</td>\n", |
| 134 | + " </tr>\n", |
| 135 | + " </tbody>\n", |
| 136 | + "</table>\n", |
| 137 | + "</div>" |
| 138 | + ], |
| 139 | + "text/plain": [ |
| 140 | + " Avg. Area Income \\\n", |
| 141 | + "Address \n", |
| 142 | + "208 Michael Ferry Apt. 674\\r\\nLaurabury, NE 370... 79545.458574 \n", |
| 143 | + "188 Johnson Views Suite 079\\r\\nLake Kathleen, C... 79248.642455 \n", |
| 144 | + "9127 Elizabeth Stravenue\\r\\nDanieltown, WI 0648... 61287.067179 \n", |
| 145 | + "\n", |
| 146 | + " Avg. Area House Age \\\n", |
| 147 | + "Address \n", |
| 148 | + "208 Michael Ferry Apt. 674\\r\\nLaurabury, NE 370... 5.682861 \n", |
| 149 | + "188 Johnson Views Suite 079\\r\\nLake Kathleen, C... 6.002900 \n", |
| 150 | + "9127 Elizabeth Stravenue\\r\\nDanieltown, WI 0648... 5.865890 \n", |
| 151 | + "\n", |
| 152 | + " Avg. Area Number of Rooms \n", |
| 153 | + "Address \n", |
| 154 | + "208 Michael Ferry Apt. 674\\r\\nLaurabury, NE 370... 7.009188 \n", |
| 155 | + "188 Johnson Views Suite 079\\r\\nLake Kathleen, C... 6.730821 \n", |
| 156 | + "9127 Elizabeth Stravenue\\r\\nDanieltown, WI 0648... 8.512727 " |
| 157 | + ] |
| 158 | + }, |
| 159 | + "execution_count": 25, |
| 160 | + "metadata": {}, |
| 161 | + "output_type": "execute_result" |
| 162 | + } |
| 163 | + ], |
| 164 | + "source": [ |
| 165 | + "df.iloc[0:3, 0:3] " |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": 41, |
| 171 | + "id": "flexible-stomach", |
| 172 | + "metadata": {}, |
| 173 | + "outputs": [ |
| 174 | + { |
| 175 | + "data": { |
| 176 | + "text/html": [ |
| 177 | + "<div>\n", |
| 178 | + "<style scoped>\n", |
| 179 | + " .dataframe tbody tr th:only-of-type {\n", |
| 180 | + " vertical-align: middle;\n", |
| 181 | + " }\n", |
| 182 | + "\n", |
| 183 | + " .dataframe tbody tr th {\n", |
| 184 | + " vertical-align: top;\n", |
| 185 | + " }\n", |
| 186 | + "\n", |
| 187 | + " .dataframe thead th {\n", |
| 188 | + " text-align: right;\n", |
| 189 | + " }\n", |
| 190 | + "</style>\n", |
| 191 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 192 | + " <thead>\n", |
| 193 | + " <tr style=\"text-align: right;\">\n", |
| 194 | + " <th></th>\n", |
| 195 | + " <th>Avg. Area Income</th>\n", |
| 196 | + " <th>Avg. Area House Age</th>\n", |
| 197 | + " </tr>\n", |
| 198 | + " </thead>\n", |
| 199 | + " <tbody>\n", |
| 200 | + " <tr>\n", |
| 201 | + " <th>0</th>\n", |
| 202 | + " <td>79545.458574</td>\n", |
| 203 | + " <td>5.682861</td>\n", |
| 204 | + " </tr>\n", |
| 205 | + " <tr>\n", |
| 206 | + " <th>1</th>\n", |
| 207 | + " <td>79248.642455</td>\n", |
| 208 | + " <td>6.002900</td>\n", |
| 209 | + " </tr>\n", |
| 210 | + " <tr>\n", |
| 211 | + " <th>2</th>\n", |
| 212 | + " <td>61287.067179</td>\n", |
| 213 | + " <td>5.865890</td>\n", |
| 214 | + " </tr>\n", |
| 215 | + " <tr>\n", |
| 216 | + " <th>3</th>\n", |
| 217 | + " <td>63345.240046</td>\n", |
| 218 | + " <td>7.188236</td>\n", |
| 219 | + " </tr>\n", |
| 220 | + " <tr>\n", |
| 221 | + " <th>4</th>\n", |
| 222 | + " <td>59982.197226</td>\n", |
| 223 | + " <td>5.040555</td>\n", |
| 224 | + " </tr>\n", |
| 225 | + " </tbody>\n", |
| 226 | + "</table>\n", |
| 227 | + "</div>" |
| 228 | + ], |
| 229 | + "text/plain": [ |
| 230 | + " Avg. Area Income Avg. Area House Age\n", |
| 231 | + "0 79545.458574 5.682861\n", |
| 232 | + "1 79248.642455 6.002900\n", |
| 233 | + "2 61287.067179 5.865890\n", |
| 234 | + "3 63345.240046 7.188236\n", |
| 235 | + "4 59982.197226 5.040555" |
| 236 | + ] |
| 237 | + }, |
| 238 | + "execution_count": 41, |
| 239 | + "metadata": {}, |
| 240 | + "output_type": "execute_result" |
| 241 | + } |
| 242 | + ], |
| 243 | + "source": [ |
| 244 | + "df.loc[0:4,[\"Avg. Area Income\", \"Avg. Area House Age\"]] # index가 defualt 인 숫자로 되어있을 때만 가능" |
| 245 | + ] |
| 246 | + }, |
| 247 | + { |
| 248 | + "cell_type": "code", |
| 249 | + "execution_count": 45, |
| 250 | + "id": "latest-recipe", |
| 251 | + "metadata": {}, |
| 252 | + "outputs": [], |
| 253 | + "source": [ |
| 254 | + "X = df.drop('Price',axis=1)" |
| 255 | + ] |
| 256 | + }, |
| 257 | + { |
| 258 | + "cell_type": "code", |
| 259 | + "execution_count": 46, |
| 260 | + "id": "mysterious-leave", |
| 261 | + "metadata": {}, |
| 262 | + "outputs": [ |
| 263 | + { |
| 264 | + "data": { |
| 265 | + "text/plain": [ |
| 266 | + "(5000, 6)" |
| 267 | + ] |
| 268 | + }, |
| 269 | + "execution_count": 46, |
| 270 | + "metadata": {}, |
| 271 | + "output_type": "execute_result" |
| 272 | + } |
| 273 | + ], |
| 274 | + "source": [ |
| 275 | + "X.shape" |
| 276 | + ] |
| 277 | + }, |
| 278 | + { |
| 279 | + "cell_type": "code", |
| 280 | + "execution_count": 47, |
| 281 | + "id": "cooperative-management", |
| 282 | + "metadata": {}, |
| 283 | + "outputs": [ |
| 284 | + { |
| 285 | + "data": { |
| 286 | + "text/plain": [ |
| 287 | + "0 1.059034e+06\n", |
| 288 | + "1 1.505891e+06\n", |
| 289 | + "2 1.058988e+06\n", |
| 290 | + "3 1.260617e+06\n", |
| 291 | + "4 6.309435e+05\n", |
| 292 | + "5 1.068138e+06\n", |
| 293 | + "6 1.502056e+06\n", |
| 294 | + "7 1.573937e+06\n", |
| 295 | + "8 7.988695e+05\n", |
| 296 | + "9 1.545155e+06\n", |
| 297 | + "Name: Price, dtype: float64" |
| 298 | + ] |
| 299 | + }, |
| 300 | + "execution_count": 47, |
| 301 | + "metadata": {}, |
| 302 | + "output_type": "execute_result" |
| 303 | + } |
| 304 | + ], |
| 305 | + "source": [ |
| 306 | + "y = df['Price']\n", |
| 307 | + "y.head(10)" |
| 308 | + ] |
| 309 | + }, |
| 310 | + { |
| 311 | + "cell_type": "code", |
| 312 | + "execution_count": null, |
| 313 | + "id": "vietnamese-california", |
| 314 | + "metadata": {}, |
| 315 | + "outputs": [], |
| 316 | + "source": [] |
| 317 | + } |
| 318 | + ], |
| 319 | + "metadata": { |
| 320 | + "kernelspec": { |
| 321 | + "display_name": "Python 3", |
| 322 | + "language": "python", |
| 323 | + "name": "python3" |
| 324 | + }, |
| 325 | + "language_info": { |
| 326 | + "codemirror_mode": { |
| 327 | + "name": "ipython", |
| 328 | + "version": 3 |
| 329 | + }, |
| 330 | + "file_extension": ".py", |
| 331 | + "mimetype": "text/x-python", |
| 332 | + "name": "python", |
| 333 | + "nbconvert_exporter": "python", |
| 334 | + "pygments_lexer": "ipython3", |
| 335 | + "version": "3.8.8" |
| 336 | + } |
| 337 | + }, |
| 338 | + "nbformat": 4, |
| 339 | + "nbformat_minor": 5 |
| 340 | +} |
0 commit comments