├── .gitattributes ├── .gitignore ├── Appendix A - A Crash Course in Python.ipynb ├── Chapter 1 - Installing Python, SAS SWAT, and CAS.ipynb ├── Chapter 10 - Advanced Topics.ipynb ├── Chapter 2 - The 10 Minute Guide to Using CAS from Python.ipynb ├── Chapter 3 - The Fundamentals of using Python with CAS.ipynb ├── Chapter 4 - Managing Your Data in CAS.ipynb ├── Chapter 5 - The CASAction and CASTable Objects.ipynb ├── Chapter 6 - Working with CAS Tables.ipynb ├── Chapter 7 - Data Exploration and Summary Statistics.ipynb ├── Chapter 8 - Modeling Continuous Variables.ipynb ├── Chapter 9 - Modeling Categorical Variables.ipynb ├── LICENSE ├── README.md ├── cover.jpg └── data ├── README.md └── organics.csv.zip /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | # enforce text on certain files 3 | *.py text 4 | *.pyx text 5 | *.pyd text 6 | *.c text 7 | *.h text 8 | *.html text 9 | *.csv text 10 | *.json text 11 | *.pickle binary 12 | *.h5 binary 13 | *.dta binary 14 | *.xls binary 15 | *.xlsx binary 16 | *.bat text eol=crlf 17 | *.html text 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Editor temporary/working/backup files 2 | .#* 3 | *\#*\# 4 | [#]*# 5 | *~ 6 | *$ 7 | *.bak 8 | *.old 9 | *flymake* 10 | *.kdev4 11 | *.log 12 | *.swo 13 | *.swp 14 | *.pdb 15 | .project 16 | .pydevproject 17 | .settings 18 | .idea 19 | .vagrant 20 | .noseids 21 | .ipynb_checkpoints 22 | .tags 23 | 24 | ## Compiled source 25 | *.a 26 | *.com 27 | *.class 28 | *.dll 29 | *.dylib 30 | *.exe 31 | *.o 32 | *.py[ocd] 33 | *.so 34 | .build_cache_dir 35 | MANIFEST 36 | 37 | ## Python files 38 | # setup.py working directory 39 | build 40 | # sphinx build directory 41 | doc/_build 42 | # setup.py dist directory 43 | dist 44 | # Egg metadata 45 | *.egg-info 46 | .eggs 47 | .pypirc 48 | 49 | ## tox testing tool 50 | .tox 51 | # rope 52 | .ropeproject 53 | # wheel files 54 | *.whl 55 | **/wheelhouse/* 56 | # coverage 57 | .coverage 58 | swat.egg-info/ 59 | __pycache__/ 60 | _stats.txt 61 | cover/ 62 | test-reports/ 63 | 64 | ## OS generated files 65 | .directory 66 | .gdb_history 67 | .DS_Store 68 | ehthumbs.db 69 | Icon? 70 | Thumbs.db 71 | 72 | ## Documentation generated files 73 | doc/build 74 | doc/source/generated 75 | -------------------------------------------------------------------------------- /Chapter 1 - Installing Python, SAS SWAT, and CAS.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Chapter 1 - Installing Python, SAS SWAT, and CAS\n", 8 | "\n", 9 | "After installing Python (we recommend \n", 10 | "[the Anaconda distribution from Continuum.io](https://www.continuum.io/downloads)),\n", 11 | "you can get the most recent version of SAS SWAT (Scripting Wrapper for Analytics Transfer)\n", 12 | "from GitHub at https://github.com/sassoftware/python-swat/releases. Simply run \n", 13 | "`pip install ` on the appropriate installer for your platform, or use the source\n", 14 | "code tar.gz if your platform isn't supported. In the latter case, you will need to\n", 15 | "use the REST interface of CAS. \n", 16 | "\n", 17 | "Once you have that installed and you have a CAS\n", 18 | "server available, you can make your first connection." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "## Making Your First Connection" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "import swat\n", 37 | "\n", 38 | "conn = swat.CAS('server-name.mycompany.com', port-number, 'userid', 'password')" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": { 45 | "collapsed": true 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "conn.serverstatus()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": { 56 | "collapsed": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "conn.close()" 61 | ] 62 | } 63 | ], 64 | "metadata": { 65 | "kernelspec": { 66 | "display_name": "Python 3", 67 | "language": "python", 68 | "name": "python3" 69 | }, 70 | "language_info": { 71 | "codemirror_mode": { 72 | "name": "ipython", 73 | "version": 3 74 | }, 75 | "file_extension": ".py", 76 | "mimetype": "text/x-python", 77 | "name": "python", 78 | "nbconvert_exporter": "python", 79 | "pygments_lexer": "ipython3", 80 | "version": "3.4.5" 81 | } 82 | }, 83 | "nbformat": 4, 84 | "nbformat_minor": 0 85 | } 86 | -------------------------------------------------------------------------------- /Chapter 10 - Advanced Topics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Chapter 10 - Advanced Topics" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "import swat" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": { 25 | "collapsed": true 26 | }, 27 | "outputs": [], 28 | "source": [ 29 | "conn = swat.CAS('server-name.mycompany.com', 5570, 'username', 'password')" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Binary vs REST Interfaces" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "### The Binary Interface" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "collapsed": true 51 | }, 52 | "outputs": [], 53 | "source": [ 54 | "binconn = swat.CAS('server-name.mycompany.com', 5570, protocol='cas')" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "### The REST Interface" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": { 68 | "collapsed": true 69 | }, 70 | "outputs": [], 71 | "source": [ 72 | "restconn = swat.CAS('server-name.mycompany.com', 8888, protocol='http')" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Result Processing Workflows" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "### The Easy Way" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 3, 92 | "metadata": { 93 | "collapsed": false 94 | }, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "NOTE: Cloud Analytic Services made the file data/iris.csv available as table DATA.IRIS in caslib CASUSER(username).\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "tbl = conn.loadtable('data/iris.csv', caslib='casuser').casTable" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 4, 111 | "metadata": { 112 | "collapsed": false 113 | }, 114 | "outputs": [ 115 | { 116 | "data": { 117 | "text/html": [ 118 | "
§ Summary
\n", 119 | "
\n", 120 | "
\n", 121 | "\n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | "
Descriptive Statistics for DATA.IRIS
ColumnMinMaxNNMissMeanSumStdStdErrVarUSSCSSCVTValueProbT
0sepal_length4.37.9150.00.05.843333876.50.8280660.0676110.6856945223.85102.16833314.17112686.4253753.331256e-129
1sepal_width2.04.4150.00.03.054000458.10.4335940.0354030.1880041427.0528.01260014.19758786.2642974.374977e-129
2petal_length1.06.9150.00.03.758667563.81.7644200.1440643.1131792583.00463.86373346.94272126.0901981.994305e-57
3petal_width0.12.5150.00.01.198667179.80.7631610.0623120.582414302.3086.77973363.66747019.2365883.209704e-42
\n", 217 | "
\n", 218 | "
\n", 219 | "
\n", 220 | "

elapsed 0.025s · user 0.027s · sys 0.002s · mem 1.74MB

" 221 | ], 222 | "text/plain": [ 223 | "[Summary]\n", 224 | "\n", 225 | " Descriptive Statistics for DATA.IRIS\n", 226 | " \n", 227 | " Column Min Max N NMiss Mean Sum Std StdErr \\\n", 228 | " 0 sepal_length 4.3 7.9 150.0 0.0 5.843333 876.5 0.828066 0.067611 \n", 229 | " 1 sepal_width 2.0 4.4 150.0 0.0 3.054000 458.1 0.433594 0.035403 \n", 230 | " 2 petal_length 1.0 6.9 150.0 0.0 3.758667 563.8 1.764420 0.144064 \n", 231 | " 3 petal_width 0.1 2.5 150.0 0.0 1.198667 179.8 0.763161 0.062312 \n", 232 | " \n", 233 | " Var USS CSS CV TValue ProbT \n", 234 | " 0 0.685694 5223.85 102.168333 14.171126 86.425375 3.331256e-129 \n", 235 | " 1 0.188004 1427.05 28.012600 14.197587 86.264297 4.374977e-129 \n", 236 | " 2 3.113179 2583.00 463.863733 46.942721 26.090198 1.994305e-57 \n", 237 | " 3 0.582414 302.30 86.779733 63.667470 19.236588 3.209704e-42 \n", 238 | "\n", 239 | "+ Elapsed: 0.025s, user: 0.027s, sys: 0.002s, mem: 1.74mb" 240 | ] 241 | }, 242 | "execution_count": 4, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "out = tbl.summary()\n", 249 | "out" 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "metadata": {}, 255 | "source": [ 256 | "### Using Response and Result Callbacks" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 5, 262 | "metadata": { 263 | "collapsed": true 264 | }, 265 | "outputs": [], 266 | "source": [ 267 | "def result_cb(key, value, response, connection, userdata):\n", 268 | " print('\\n>>> RESULT %s\\n' % key)\n", 269 | " print(value)\n", 270 | " return userdata" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 7, 276 | "metadata": { 277 | "collapsed": false 278 | }, 279 | "outputs": [ 280 | { 281 | "name": "stdout", 282 | "output_type": "stream", 283 | "text": [ 284 | "\n", 285 | ">>> RESULT ByGroupInfo\n", 286 | "\n", 287 | "ByGroupInfo\n", 288 | "\n", 289 | " species species_f _key_\n", 290 | "0 setosa setosa setosa\n", 291 | "1 versicolor versicolor versicolor\n", 292 | "2 virginica virginica virginica\n", 293 | "\n", 294 | ">>> RESULT ByGroup1.Summary\n", 295 | "\n", 296 | "Descriptive Statistics for DATA.IRIS\n", 297 | "\n", 298 | " Column Min Max\n", 299 | "species \n", 300 | "setosa sepal_length 4.3 5.8\n", 301 | "setosa sepal_width 2.3 4.4\n", 302 | "setosa petal_length 1.0 1.9\n", 303 | "setosa petal_width 0.1 0.6\n", 304 | "\n", 305 | ">>> RESULT ByGroup2.Summary\n", 306 | "\n", 307 | "Descriptive Statistics for DATA.IRIS\n", 308 | "\n", 309 | " Column Min Max\n", 310 | "species \n", 311 | "versicolor sepal_length 4.9 7.0\n", 312 | "versicolor sepal_width 2.0 3.4\n", 313 | "versicolor petal_length 3.0 5.1\n", 314 | "versicolor petal_width 1.0 1.8\n", 315 | "\n", 316 | ">>> RESULT ByGroup3.Summary\n", 317 | "\n", 318 | "Descriptive Statistics for DATA.IRIS\n", 319 | "\n", 320 | " Column Min Max\n", 321 | "species \n", 322 | "virginica sepal_length 4.9 7.9\n", 323 | "virginica sepal_width 2.2 3.8\n", 324 | "virginica petal_length 4.5 6.9\n", 325 | "virginica petal_width 1.4 2.5\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "tbl.groupby('species').summary(resultfunc=result_cb, subset=['min', 'max'])" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 8, 336 | "metadata": { 337 | "collapsed": true 338 | }, 339 | "outputs": [], 340 | "source": [ 341 | "def response_cb(response, connection, userdata):\n", 342 | " print('\\n>>> RESPONSE')\n", 343 | " for k, v in response:\n", 344 | " print('\\n>>> RESULT %s\\n' % k)\n", 345 | " print(v)\n", 346 | " return userdata" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 9, 352 | "metadata": { 353 | "collapsed": false 354 | }, 355 | "outputs": [ 356 | { 357 | "name": "stdout", 358 | "output_type": "stream", 359 | "text": [ 360 | "\n", 361 | ">>> RESPONSE\n", 362 | "\n", 363 | ">>> RESULT ByGroupInfo\n", 364 | "\n", 365 | "ByGroupInfo\n", 366 | "\n", 367 | " species species_f _key_\n", 368 | "0 setosa setosa setosa\n", 369 | "1 versicolor versicolor versicolor\n", 370 | "2 virginica virginica virginica\n", 371 | "\n", 372 | ">>> RESPONSE\n", 373 | "\n", 374 | ">>> RESULT ByGroup1.Summary\n", 375 | "\n", 376 | "Descriptive Statistics for DATA.IRIS\n", 377 | "\n", 378 | " Column Min Max\n", 379 | "species \n", 380 | "setosa sepal_length 4.3 5.8\n", 381 | "setosa sepal_width 2.3 4.4\n", 382 | "setosa petal_length 1.0 1.9\n", 383 | "setosa petal_width 0.1 0.6\n", 384 | "\n", 385 | ">>> RESPONSE\n", 386 | "\n", 387 | ">>> RESULT ByGroup2.Summary\n", 388 | "\n", 389 | "Descriptive Statistics for DATA.IRIS\n", 390 | "\n", 391 | " Column Min Max\n", 392 | "species \n", 393 | "versicolor sepal_length 4.9 7.0\n", 394 | "versicolor sepal_width 2.0 3.4\n", 395 | "versicolor petal_length 3.0 5.1\n", 396 | "versicolor petal_width 1.0 1.8\n", 397 | "\n", 398 | ">>> RESPONSE\n", 399 | "\n", 400 | ">>> RESULT ByGroup3.Summary\n", 401 | "\n", 402 | "Descriptive Statistics for DATA.IRIS\n", 403 | "\n", 404 | " Column Min Max\n", 405 | "species \n", 406 | "virginica sepal_length 4.9 7.9\n", 407 | "virginica sepal_width 2.2 3.8\n", 408 | "virginica petal_length 4.5 6.9\n", 409 | "virginica petal_width 1.4 2.5\n", 410 | "\n", 411 | ">>> RESPONSE\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "tbl.groupby('species').summary(responsefunc=response_cb, subset=['min', 'max'])" 417 | ] 418 | }, 419 | { 420 | "cell_type": "markdown", 421 | "metadata": {}, 422 | "source": [ 423 | "### Handling Responses from Multiple Sessions Simultaneously" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 18, 429 | "metadata": { 430 | "collapsed": true 431 | }, 432 | "outputs": [], 433 | "source": [ 434 | "conn1 = swat.CAS()\n", 435 | "conn2 = swat.CAS()" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 20, 441 | "metadata": { 442 | "collapsed": false 443 | }, 444 | "outputs": [ 445 | { 446 | "name": "stdout", 447 | "output_type": "stream", 448 | "text": [ 449 | "NOTE: Cloud Analytic Services made the file data/iris.csv available as table DATA.IRIS in caslib CASUSER(username).\n", 450 | "NOTE: Cloud Analytic Services made the file data/iris.csv available as table DATA.IRIS in caslib CASUSER(username).\n" 451 | ] 452 | } 453 | ], 454 | "source": [ 455 | "tbl1 = conn1.loadtable('data/iris.csv', caslib='casuser').casTable\n", 456 | "tbl2 = conn2.loadtable('data/iris.csv', caslib='casuser').casTable" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 27, 462 | "metadata": { 463 | "collapsed": false 464 | }, 465 | "outputs": [], 466 | "source": [ 467 | "conn1 = tbl1.groupby('species').invoke('summary', subset=['min', 'max'])" 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 28, 473 | "metadata": { 474 | "collapsed": false 475 | }, 476 | "outputs": [ 477 | { 478 | "name": "stdout", 479 | "output_type": "stream", 480 | "text": [ 481 | "\n", 482 | ">>> RESPONSE\n", 483 | "\n", 484 | ">>> RESULT ByGroupInfo\n", 485 | "\n", 486 | "ByGroupInfo\n", 487 | "\n", 488 | " species species_f _key_\n", 489 | "0 setosa setosa setosa\n", 490 | "1 versicolor versicolor versicolor\n", 491 | "2 virginica virginica virginica\n", 492 | "\n", 493 | ">>> RESPONSE\n", 494 | "\n", 495 | ">>> RESULT ByGroup1.Summary\n", 496 | "\n", 497 | "Descriptive Statistics for DATA.IRIS\n", 498 | "\n", 499 | " Column Min Max\n", 500 | "species \n", 501 | "setosa sepal_length 4.3 5.8\n", 502 | "setosa sepal_width 2.3 4.4\n", 503 | "setosa petal_length 1.0 1.9\n", 504 | "setosa petal_width 0.1 0.6\n", 505 | "\n", 506 | ">>> RESPONSE\n", 507 | "\n", 508 | ">>> RESULT ByGroup2.Summary\n", 509 | "\n", 510 | "Descriptive Statistics for DATA.IRIS\n", 511 | "\n", 512 | " Column Min Max\n", 513 | "species \n", 514 | "versicolor sepal_length 4.9 7.0\n", 515 | "versicolor sepal_width 2.0 3.4\n", 516 | "versicolor petal_length 3.0 5.1\n", 517 | "versicolor petal_width 1.0 1.8\n", 518 | "\n", 519 | ">>> RESPONSE\n", 520 | "\n", 521 | ">>> RESULT ByGroup3.Summary\n", 522 | "\n", 523 | "Descriptive Statistics for DATA.IRIS\n", 524 | "\n", 525 | " Column Min Max\n", 526 | "species \n", 527 | "virginica sepal_length 4.9 7.9\n", 528 | "virginica sepal_width 2.2 3.8\n", 529 | "virginica petal_length 4.5 6.9\n", 530 | "virginica petal_width 1.4 2.5\n", 531 | "\n", 532 | ">>> RESPONSE\n" 533 | ] 534 | } 535 | ], 536 | "source": [ 537 | "for resp in conn1:\n", 538 | " print('\\n>>> RESPONSE')\n", 539 | " for k, v in resp:\n", 540 | " print('\\n>>> RESULT %s\\n' % k)\n", 541 | " print(v)" 542 | ] 543 | }, 544 | { 545 | "cell_type": "code", 546 | "execution_count": 29, 547 | "metadata": { 548 | "collapsed": true 549 | }, 550 | "outputs": [], 551 | "source": [ 552 | "conn1 = tbl1.groupby('species').invoke('summary', subset=['min', 'max'])\n", 553 | "conn2 = tbl2.groupby('species').invoke('topk', topk=1, bottomk=1)" 554 | ] 555 | }, 556 | { 557 | "cell_type": "code", 558 | "execution_count": 30, 559 | "metadata": { 560 | "collapsed": false 561 | }, 562 | "outputs": [ 563 | { 564 | "name": "stdout", 565 | "output_type": "stream", 566 | "text": [ 567 | "\n", 568 | ">>> RESPONSE\n", 569 | "\n", 570 | ">>> RESULT ByGroupInfo\n", 571 | "\n", 572 | "ByGroupInfo\n", 573 | "\n", 574 | " species species_f _key_\n", 575 | "0 setosa setosa setosa\n", 576 | "1 versicolor versicolor versicolor\n", 577 | "2 virginica virginica virginica\n", 578 | "\n", 579 | ">>> RESPONSE\n", 580 | "\n", 581 | ">>> RESULT ByGroup1.Summary\n", 582 | "\n", 583 | "Descriptive Statistics for DATA.IRIS\n", 584 | "\n", 585 | " Column Min Max\n", 586 | "species \n", 587 | "setosa sepal_length 4.3 5.8\n", 588 | "setosa sepal_width 2.3 4.4\n", 589 | "setosa petal_length 1.0 1.9\n", 590 | "setosa petal_width 0.1 0.6\n", 591 | "\n", 592 | ">>> RESPONSE\n", 593 | "\n", 594 | ">>> RESULT ByGroup2.Summary\n", 595 | "\n", 596 | "Descriptive Statistics for DATA.IRIS\n", 597 | "\n", 598 | " Column Min Max\n", 599 | "species \n", 600 | "versicolor sepal_length 4.9 7.0\n", 601 | "versicolor sepal_width 2.0 3.4\n", 602 | "versicolor petal_length 3.0 5.1\n", 603 | "versicolor petal_width 1.0 1.8\n", 604 | "\n", 605 | ">>> RESPONSE\n", 606 | "\n", 607 | ">>> RESULT ByGroup3.Summary\n", 608 | "\n", 609 | "Descriptive Statistics for DATA.IRIS\n", 610 | "\n", 611 | " Column Min Max\n", 612 | "species \n", 613 | "virginica sepal_length 4.9 7.9\n", 614 | "virginica sepal_width 2.2 3.8\n", 615 | "virginica petal_length 4.5 6.9\n", 616 | "virginica petal_width 1.4 2.5\n", 617 | "\n", 618 | ">>> RESPONSE\n", 619 | "\n", 620 | ">>> RESPONSE\n", 621 | "\n", 622 | ">>> RESULT ByGroupInfo\n", 623 | "\n", 624 | "ByGroupInfo\n", 625 | "\n", 626 | " species species_f _key_\n", 627 | "0 setosa setosa setosa\n", 628 | "1 versicolor versicolor versicolor\n", 629 | "2 virginica virginica virginica\n", 630 | "\n", 631 | ">>> RESPONSE\n", 632 | "\n", 633 | ">>> RESULT ByGroup1.Topk\n", 634 | "\n", 635 | "Top and Bottom Distinct Values for DATA.IRIS\n", 636 | "\n", 637 | " Column FmtVar Rank\n", 638 | "species \n", 639 | "setosa sepal_length 5.8 1\n", 640 | "setosa sepal_length 5 15\n", 641 | "setosa sepal_width 4.4 1\n", 642 | "setosa sepal_width 3 16\n", 643 | "setosa petal_length 1.9 1\n", 644 | "setosa petal_length 1 9\n", 645 | "setosa petal_width 0.6 1\n", 646 | "setosa petal_width 0.1 6\n", 647 | "setosa species setosa 1\n", 648 | "setosa species setosa 1\n", 649 | "\n", 650 | ">>> RESPONSE\n", 651 | "\n", 652 | ">>> RESULT ByGroup1.TopkMisc\n", 653 | "\n", 654 | "Miscellaneous Information on Distinct Values for DATA.IRIS\n", 655 | "\n", 656 | " Column N TruncatedTopk TruncatedBtmk ScoreOther\n", 657 | "species \n", 658 | "setosa sepal_length 15 0 0 NaN\n", 659 | "setosa sepal_width 16 0 0 NaN\n", 660 | "setosa petal_length 9 0 0 NaN\n", 661 | "setosa petal_width 6 0 0 NaN\n", 662 | "setosa species 1 0 0 NaN\n", 663 | "\n", 664 | ">>> RESPONSE\n", 665 | "\n", 666 | ">>> RESULT ByGroup2.Topk\n", 667 | "\n", 668 | "Top and Bottom Distinct Values for DATA.IRIS\n", 669 | "\n", 670 | " Column FmtVar Rank\n", 671 | "species \n", 672 | "versicolor sepal_length 6.9 1\n", 673 | "versicolor sepal_length 5 21\n", 674 | "versicolor sepal_width 3.4 1\n", 675 | "versicolor sepal_width 2 14\n", 676 | "versicolor petal_length 5.1 1\n", 677 | "versicolor petal_length 3 19\n", 678 | "versicolor petal_width 1.8 1\n", 679 | "versicolor petal_width 1 9\n", 680 | "versicolor species versicolor 1\n", 681 | "versicolor species versicolor 1\n", 682 | "\n", 683 | ">>> RESPONSE\n", 684 | "\n", 685 | ">>> RESULT ByGroup2.TopkMisc\n", 686 | "\n", 687 | "Miscellaneous Information on Distinct Values for DATA.IRIS\n", 688 | "\n", 689 | " Column N TruncatedTopk TruncatedBtmk ScoreOther\n", 690 | "species \n", 691 | "versicolor sepal_length 21 0 0 NaN\n", 692 | "versicolor sepal_width 14 0 0 NaN\n", 693 | "versicolor petal_length 19 0 0 NaN\n", 694 | "versicolor petal_width 9 0 0 NaN\n", 695 | "versicolor species 1 0 0 NaN\n", 696 | "\n", 697 | ">>> RESPONSE\n", 698 | "\n", 699 | ">>> RESULT ByGroup3.Topk\n", 700 | "\n", 701 | "Top and Bottom Distinct Values for DATA.IRIS\n", 702 | "\n", 703 | " Column FmtVar Rank\n", 704 | "species \n", 705 | "virginica sepal_length 7.9 1\n", 706 | "virginica sepal_length 6 21\n", 707 | "virginica sepal_width 3.8 1\n", 708 | "virginica sepal_width 3 13\n", 709 | "virginica petal_length 6.9 1\n", 710 | "virginica petal_length 5 20\n", 711 | "virginica petal_width 2.5 1\n", 712 | "virginica petal_width 2 12\n", 713 | "virginica species virginica 1\n", 714 | "virginica species virginica 1\n", 715 | "\n", 716 | ">>> RESPONSE\n", 717 | "\n", 718 | ">>> RESULT ByGroup3.TopkMisc\n", 719 | "\n", 720 | "Miscellaneous Information on Distinct Values for DATA.IRIS\n", 721 | "\n", 722 | " Column N TruncatedTopk TruncatedBtmk ScoreOther\n", 723 | "species \n", 724 | "virginica sepal_length 21 0 0 NaN\n", 725 | "virginica sepal_width 13 0 0 NaN\n", 726 | "virginica petal_length 20 0 0 NaN\n", 727 | "virginica petal_width 12 0 0 NaN\n", 728 | "virginica species 1 0 0 NaN\n", 729 | "\n", 730 | ">>> RESPONSE\n" 731 | ] 732 | } 733 | ], 734 | "source": [ 735 | "for resp, c in swat.getnext(conn1, conn2):\n", 736 | " print('\\n>>> RESPONSE')\n", 737 | " for k, v in resp:\n", 738 | " print('\\n>>> RESULT %s\\n' % k)\n", 739 | " print(v)" 740 | ] 741 | }, 742 | { 743 | "cell_type": "markdown", 744 | "metadata": {}, 745 | "source": [ 746 | "## Connecting to Existing Sessions" 747 | ] 748 | }, 749 | { 750 | "cell_type": "code", 751 | "execution_count": 31, 752 | "metadata": { 753 | "collapsed": false 754 | }, 755 | "outputs": [ 756 | { 757 | "data": { 758 | "text/plain": [ 759 | "CAS('server-name.mycompany.com', 5570, 'username', protocol='cas', name='py-session-1', session='2fed25d6-4946-0540-8308-73c7f75b53c6')" 760 | ] 761 | }, 762 | "execution_count": 31, 763 | "metadata": {}, 764 | "output_type": "execute_result" 765 | } 766 | ], 767 | "source": [ 768 | "conn" 769 | ] 770 | }, 771 | { 772 | "cell_type": "code", 773 | "execution_count": 32, 774 | "metadata": { 775 | "collapsed": false 776 | }, 777 | "outputs": [ 778 | { 779 | "data": { 780 | "text/html": [ 781 | "
§ Session
\n", 782 | "
\n", 783 | "
\n", 784 | "\n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | "
SessionNameUUIDStateAuthenticationUserid
0py-session-3:Fri Nov 4 10:32:16 2016e7f753f7-4e20-aa46-ac6a-4c574cede3c5ConnectedActive Directoryusername
1py-session-1:Fri Nov 4 11:46:25 20162fed25d6-4946-0540-8308-73c7f75b53c6ConnectedActive Directoryusername
2py-session-2:Fri Nov 4 12:06:29 20166f04be18-1146-0642-8437-9e928edbf42dConnectedActive Directoryusername
3py-session-4:Fri Nov 4 12:08:52 201621e426a9-20f8-ef4e-a606-cc699f8e274aConnectedActive Directoryusername
4py-session-5:Fri Nov 4 12:08:52 2016430d8336-2b9b-f54b-8163-86ebe476b238ConnectedActive Directoryusername
\n", 838 | "
\n", 839 | "
\n", 840 | "
\n", 841 | "

elapsed 0.000406s · mem 0.0912MB

" 842 | ], 843 | "text/plain": [ 844 | "[Session]\n", 845 | "\n", 846 | " SessionName \\\n", 847 | " 0 py-session-3:Fri Nov 4 10:32:16 2016 \n", 848 | " 1 py-session-1:Fri Nov 4 11:46:25 2016 \n", 849 | " 2 py-session-2:Fri Nov 4 12:06:29 2016 \n", 850 | " 3 py-session-4:Fri Nov 4 12:08:52 2016 \n", 851 | " 4 py-session-5:Fri Nov 4 12:08:52 2016 \n", 852 | " \n", 853 | " UUID State Authentication Userid \n", 854 | " 0 e7f753f7-4e20-aa46-ac6a-4c574cede3c5 Connected Active Directory username \n", 855 | " 1 2fed25d6-4946-0540-8308-73c7f75b53c6 Connected Active Directory username \n", 856 | " 2 6f04be18-1146-0642-8437-9e928edbf42d Connected Active Directory username \n", 857 | " 3 21e426a9-20f8-ef4e-a606-cc699f8e274a Connected Active Directory username \n", 858 | " 4 430d8336-2b9b-f54b-8163-86ebe476b238 Connected Active Directory username \n", 859 | "\n", 860 | "+ Elapsed: 0.000406s, mem: 0.0912mb" 861 | ] 862 | }, 863 | "execution_count": 32, 864 | "metadata": {}, 865 | "output_type": "execute_result" 866 | } 867 | ], 868 | "source": [ 869 | "conn.listsessions()" 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": 33, 875 | "metadata": { 876 | "collapsed": true 877 | }, 878 | "outputs": [], 879 | "source": [ 880 | "conn2 = swat.CAS('server-name.mycompany.com', 5570, session='2fed25d6-4946-0540-8308-73c7f75b53c6')" 881 | ] 882 | }, 883 | { 884 | "cell_type": "code", 885 | "execution_count": 34, 886 | "metadata": { 887 | "collapsed": false 888 | }, 889 | "outputs": [ 890 | { 891 | "data": { 892 | "text/plain": [ 893 | "CAS('server-name.mycompany.com', 5570, 'username', protocol='cas', name='py-session-6', session='2fed25d6-4946-0540-8308-73c7f75b53c6')" 894 | ] 895 | }, 896 | "execution_count": 34, 897 | "metadata": {}, 898 | "output_type": "execute_result" 899 | } 900 | ], 901 | "source": [ 902 | "conn2" 903 | ] 904 | }, 905 | { 906 | "cell_type": "code", 907 | "execution_count": null, 908 | "metadata": { 909 | "collapsed": true 910 | }, 911 | "outputs": [], 912 | "source": [] 913 | } 914 | ], 915 | "metadata": { 916 | "kernelspec": { 917 | "display_name": "Python 3", 918 | "language": "python", 919 | "name": "python3" 920 | }, 921 | "language_info": { 922 | "codemirror_mode": { 923 | "name": "ipython", 924 | "version": 3 925 | }, 926 | "file_extension": ".py", 927 | "mimetype": "text/x-python", 928 | "name": "python", 929 | "nbconvert_exporter": "python", 930 | "pygments_lexer": "ipython3", 931 | "version": "3.4.5" 932 | } 933 | }, 934 | "nbformat": 4, 935 | "nbformat_minor": 0 936 | } 937 | -------------------------------------------------------------------------------- /Chapter 5 - The CASAction and CASTable Objects.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Chapter 5 - The CASAction and CASTable Objects" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Getting Started with CASAction Objects" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": { 21 | "collapsed": true 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "import swat" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "conn = swat.CAS('server-name.mycompany.com', 5570, 'username', 'password')" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "conn.fetch?" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "Create an instance of the Fetch object." 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": { 61 | "collapsed": true 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "fa = conn.Fetch()" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 4, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "swat.cas.actions.table.Fetch" 79 | ] 80 | }, 81 | "execution_count": 4, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "type(fa)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": { 94 | "collapsed": false 95 | }, 96 | "outputs": [ 97 | { 98 | "data": { 99 | "text/plain": [ 100 | "(swat.cas.actions.CASAction,)" 101 | ] 102 | }, 103 | "execution_count": 5, 104 | "metadata": {}, 105 | "output_type": "execute_result" 106 | } 107 | ], 108 | "source": [ 109 | "type(fa).__bases__" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 6, 115 | "metadata": { 116 | "collapsed": false 117 | }, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "NOTE: Cloud Analytic Services made the file data/iris.csv available as table DATA.IRIS in caslib CASUSER(username).\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "out = conn.loadtable('data/iris.csv', caslib='casuser')" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "Call the CASAction instance." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 7, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/html": [ 148 | "
§ Fetch
\n", 149 | "
\n", 150 | "
\n", 151 | "\n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
45.03.61.40.2setosa
\n", 205 | "
\n", 206 | "
\n", 207 | "
\n", 208 | "

elapsed 0.00369s · user 0.002s · sys 0.001s · mem 1.65MB

" 209 | ], 210 | "text/plain": [ 211 | "[Fetch]\n", 212 | "\n", 213 | " Selected Rows from Table DATA.IRIS\n", 214 | " \n", 215 | " sepal_length sepal_width petal_length petal_width species\n", 216 | " 0 5.1 3.5 1.4 0.2 setosa\n", 217 | " 1 4.9 3.0 1.4 0.2 setosa\n", 218 | " 2 4.7 3.2 1.3 0.2 setosa\n", 219 | " 3 4.6 3.1 1.5 0.2 setosa\n", 220 | " 4 5.0 3.6 1.4 0.2 setosa\n", 221 | "\n", 222 | "+ Elapsed: 0.00369s, user: 0.002s, sys: 0.001s, mem: 1.65mb" 223 | ] 224 | }, 225 | "execution_count": 7, 226 | "metadata": {}, 227 | "output_type": "execute_result" 228 | } 229 | ], 230 | "source": [ 231 | "fa(table=dict(name='data.iris', caslib='casuser'), to=5)" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": 8, 237 | "metadata": { 238 | "collapsed": false 239 | }, 240 | "outputs": [ 241 | { 242 | "data": { 243 | "text/html": [ 244 | "
§ Fetch
\n", 245 | "
\n", 246 | "
\n", 247 | "\n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
04.33.01.10.1setosa
14.42.91.40.2setosa
24.43.01.30.2setosa
34.43.21.30.2setosa
44.52.31.30.3setosa
\n", 301 | "
\n", 302 | "
\n", 303 | "
\n", 304 | "

elapsed 0.0145s · user 0.008s · sys 0.006s · mem 8.58MB

" 305 | ], 306 | "text/plain": [ 307 | "[Fetch]\n", 308 | "\n", 309 | " Selected Rows from Table DATA.IRIS\n", 310 | " \n", 311 | " sepal_length sepal_width petal_length petal_width species\n", 312 | " 0 4.3 3.0 1.1 0.1 setosa\n", 313 | " 1 4.4 2.9 1.4 0.2 setosa\n", 314 | " 2 4.4 3.0 1.3 0.2 setosa\n", 315 | " 3 4.4 3.2 1.3 0.2 setosa\n", 316 | " 4 4.5 2.3 1.3 0.3 setosa\n", 317 | "\n", 318 | "+ Elapsed: 0.0145s, user: 0.008s, sys: 0.006s, mem: 8.58mb" 319 | ] 320 | }, 321 | "execution_count": 8, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "fa(table=dict(name='data.iris', caslib='casuser'), to=5,\n", 328 | " sortby=['sepal_length', 'sepal_width'])" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "metadata": {}, 334 | "source": [ 335 | "Set additional parameters." 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 9, 341 | "metadata": { 342 | "collapsed": false 343 | }, 344 | "outputs": [ 345 | { 346 | "data": { 347 | "text/plain": [ 348 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 349 | ] 350 | }, 351 | "execution_count": 9, 352 | "metadata": {}, 353 | "output_type": "execute_result" 354 | } 355 | ], 356 | "source": [ 357 | "fa.set_params('table', dict(name='data.iris', caslib='casuser'),\n", 358 | " 'to', 5)\n", 359 | "fa" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 10, 365 | "metadata": { 366 | "collapsed": false 367 | }, 368 | "outputs": [ 369 | { 370 | "data": { 371 | "text/html": [ 372 | "
§ Fetch
\n", 373 | "
\n", 374 | "
\n", 375 | "\n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
45.03.61.40.2setosa
\n", 429 | "
\n", 430 | "
\n", 431 | "
\n", 432 | "

elapsed 0.00335s · user 0.003s · sys 0.001s · mem 1.64MB

" 433 | ], 434 | "text/plain": [ 435 | "[Fetch]\n", 436 | "\n", 437 | " Selected Rows from Table DATA.IRIS\n", 438 | " \n", 439 | " sepal_length sepal_width petal_length petal_width species\n", 440 | " 0 5.1 3.5 1.4 0.2 setosa\n", 441 | " 1 4.9 3.0 1.4 0.2 setosa\n", 442 | " 2 4.7 3.2 1.3 0.2 setosa\n", 443 | " 3 4.6 3.1 1.5 0.2 setosa\n", 444 | " 4 5.0 3.6 1.4 0.2 setosa\n", 445 | "\n", 446 | "+ Elapsed: 0.00335s, user: 0.003s, sys: 0.001s, mem: 1.64mb" 447 | ] 448 | }, 449 | "execution_count": 10, 450 | "metadata": {}, 451 | "output_type": "execute_result" 452 | } 453 | ], 454 | "source": [ 455 | "fa()" 456 | ] 457 | }, 458 | { 459 | "cell_type": "markdown", 460 | "metadata": {}, 461 | "source": [ 462 | "Alternative ways of setting parameters. These are all equivalent." 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": 13, 468 | "metadata": { 469 | "collapsed": false 470 | }, 471 | "outputs": [ 472 | { 473 | "data": { 474 | "text/plain": [ 475 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 476 | ] 477 | }, 478 | "execution_count": 13, 479 | "metadata": {}, 480 | "output_type": "execute_result" 481 | } 482 | ], 483 | "source": [ 484 | "fa.set_params(('table', dict(name='data.iris', caslib='casuser')),\n", 485 | " ('to', 5))\n", 486 | "fa" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": 14, 492 | "metadata": { 493 | "collapsed": false 494 | }, 495 | "outputs": [ 496 | { 497 | "data": { 498 | "text/plain": [ 499 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 500 | ] 501 | }, 502 | "execution_count": 14, 503 | "metadata": {}, 504 | "output_type": "execute_result" 505 | } 506 | ], 507 | "source": [ 508 | "fa.set_params({'table': dict(name='data.iris', caslib='casuser'),\n", 509 | " 'to': 5})\n", 510 | "fa" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 15, 516 | "metadata": { 517 | "collapsed": false 518 | }, 519 | "outputs": [ 520 | { 521 | "data": { 522 | "text/plain": [ 523 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 524 | ] 525 | }, 526 | "execution_count": 15, 527 | "metadata": {}, 528 | "output_type": "execute_result" 529 | } 530 | ], 531 | "source": [ 532 | "fa.set_params(table=dict(name='data.iris', caslib='casuser'),\n", 533 | " to=5)\n", 534 | "fa" 535 | ] 536 | }, 537 | { 538 | "cell_type": "markdown", 539 | "metadata": {}, 540 | "source": [ 541 | "### Setting Nested Parameters" 542 | ] 543 | }, 544 | { 545 | "cell_type": "code", 546 | "execution_count": 16, 547 | "metadata": { 548 | "collapsed": true 549 | }, 550 | "outputs": [], 551 | "source": [ 552 | "fa = conn.Fetch()" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": 17, 558 | "metadata": { 559 | "collapsed": false 560 | }, 561 | "outputs": [ 562 | { 563 | "data": { 564 | "text/plain": [ 565 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'))" 566 | ] 567 | }, 568 | "execution_count": 17, 569 | "metadata": {}, 570 | "output_type": "execute_result" 571 | } 572 | ], 573 | "source": [ 574 | "fa.set_params('table.name', 'data.iris',\n", 575 | " 'table.caslib', 'casuser')\n", 576 | "fa" 577 | ] 578 | }, 579 | { 580 | "cell_type": "code", 581 | "execution_count": 18, 582 | "metadata": { 583 | "collapsed": false 584 | }, 585 | "outputs": [ 586 | { 587 | "data": { 588 | "text/plain": [ 589 | "?.table.Fetch(sortby=dict(0=dict(formatted='raw', name='petal_length'), 1=dict(formatted='raw', name='petal_width')), table=dict(caslib='casuser', name='data.iris'))" 590 | ] 591 | }, 592 | "execution_count": 18, 593 | "metadata": {}, 594 | "output_type": "execute_result" 595 | } 596 | ], 597 | "source": [ 598 | "fa.set_params('sortby.0.name', 'petal_length',\n", 599 | " 'sortby.0.formatted', 'raw',\n", 600 | " 'sortby.1.name', 'petal_width',\n", 601 | " 'sortby.1.formatted', 'raw')\n", 602 | "fa" 603 | ] 604 | }, 605 | { 606 | "cell_type": "code", 607 | "execution_count": 19, 608 | "metadata": { 609 | "collapsed": false 610 | }, 611 | "outputs": [ 612 | { 613 | "data": { 614 | "text/html": [ 615 | "
§ Fetch
\n", 616 | "
\n", 617 | "
\n", 618 | "\n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | " \n", 640 | " \n", 641 | " \n", 642 | " \n", 643 | " \n", 644 | " \n", 645 | " \n", 646 | " \n", 647 | " \n", 648 | " \n", 649 | " \n", 650 | " \n", 651 | " \n", 652 | " \n", 653 | " \n", 654 | " \n", 655 | " \n", 656 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
04.63.61.00.2setosa
14.33.01.10.1setosa
25.03.21.20.2setosa
35.84.01.20.2setosa
44.73.21.30.2setosa
\n", 672 | "
\n", 673 | "
\n", 674 | "
\n", 675 | "

elapsed 0.0134s · user 0.011s · sys 0.002s · mem 8.58MB

" 676 | ], 677 | "text/plain": [ 678 | "[Fetch]\n", 679 | "\n", 680 | " Selected Rows from Table DATA.IRIS\n", 681 | " \n", 682 | " sepal_length sepal_width petal_length petal_width species\n", 683 | " 0 4.6 3.6 1.0 0.2 setosa\n", 684 | " 1 4.3 3.0 1.1 0.1 setosa\n", 685 | " 2 5.0 3.2 1.2 0.2 setosa\n", 686 | " 3 5.8 4.0 1.2 0.2 setosa\n", 687 | " 4 4.7 3.2 1.3 0.2 setosa\n", 688 | "\n", 689 | "+ Elapsed: 0.0134s, user: 0.011s, sys: 0.002s, mem: 8.58mb" 690 | ] 691 | }, 692 | "execution_count": 19, 693 | "metadata": {}, 694 | "output_type": "execute_result" 695 | } 696 | ], 697 | "source": [ 698 | "fa(to=5)" 699 | ] 700 | }, 701 | { 702 | "cell_type": "markdown", 703 | "metadata": {}, 704 | "source": [ 705 | "### Setting Parameters as Attributes" 706 | ] 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 20, 711 | "metadata": { 712 | "collapsed": true 713 | }, 714 | "outputs": [], 715 | "source": [ 716 | "fa = conn.Fetch()" 717 | ] 718 | }, 719 | { 720 | "cell_type": "code", 721 | "execution_count": 21, 722 | "metadata": { 723 | "collapsed": false 724 | }, 725 | "outputs": [ 726 | { 727 | "data": { 728 | "text/plain": [ 729 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'))" 730 | ] 731 | }, 732 | "execution_count": 21, 733 | "metadata": {}, 734 | "output_type": "execute_result" 735 | } 736 | ], 737 | "source": [ 738 | "fa.params.table.name = 'data.iris'\n", 739 | "fa.params.table.caslib = 'casuser'\n", 740 | "fa" 741 | ] 742 | }, 743 | { 744 | "cell_type": "code", 745 | "execution_count": 22, 746 | "metadata": { 747 | "collapsed": false 748 | }, 749 | "outputs": [ 750 | { 751 | "data": { 752 | "text/plain": [ 753 | "?.table.Fetch(sortby=[dict(formatted='raw', name='petal_width'), dict(formatted='raw', name='petal_length')], table=dict(caslib='casuser', name='data.iris'))" 754 | ] 755 | }, 756 | "execution_count": 22, 757 | "metadata": {}, 758 | "output_type": "execute_result" 759 | } 760 | ], 761 | "source": [ 762 | "fa.params.sortby[0].name = 'petal_width'\n", 763 | "fa.params.sortby[0].formatted = 'raw'\n", 764 | "fa.params.sortby[1].name = 'petal_length'\n", 765 | "fa.params.sortby[1].formatted = 'raw'\n", 766 | "fa" 767 | ] 768 | }, 769 | { 770 | "cell_type": "markdown", 771 | "metadata": {}, 772 | "source": [ 773 | "You can save typing by creating a sortby variable first." 774 | ] 775 | }, 776 | { 777 | "cell_type": "code", 778 | "execution_count": 25, 779 | "metadata": { 780 | "collapsed": false 781 | }, 782 | "outputs": [ 783 | { 784 | "data": { 785 | "text/plain": [ 786 | "{0: {'formatted': 'raw', 'name': 'petal_width'},\n", 787 | " 1: {'formatted': 'raw', 'name': 'petal_length'}}" 788 | ] 789 | }, 790 | "execution_count": 25, 791 | "metadata": {}, 792 | "output_type": "execute_result" 793 | } 794 | ], 795 | "source": [ 796 | "sortby = fa.params.table.sortby\n", 797 | "sortby[0].name = 'petal_width'\n", 798 | "sortby[0].formatted = 'raw'\n", 799 | "sortby[1].name = 'petal_length'\n", 800 | "sortby[1].formatted = 'raw'\n", 801 | "sortby" 802 | ] 803 | }, 804 | { 805 | "cell_type": "markdown", 806 | "metadata": {}, 807 | "source": [ 808 | "Be careful of name collisions with dictionary method names!" 809 | ] 810 | }, 811 | { 812 | "cell_type": "code", 813 | "execution_count": 29, 814 | "metadata": { 815 | "collapsed": false 816 | }, 817 | "outputs": [], 818 | "source": [ 819 | "fa.params.pop = 'corn'" 820 | ] 821 | }, 822 | { 823 | "cell_type": "markdown", 824 | "metadata": {}, 825 | "source": [ 826 | "This returns the dictionary method, not the value we just added to the parameters." 827 | ] 828 | }, 829 | { 830 | "cell_type": "code", 831 | "execution_count": 31, 832 | "metadata": { 833 | "collapsed": false 834 | }, 835 | "outputs": [ 836 | { 837 | "data": { 838 | "text/plain": [ 839 | "" 840 | ] 841 | }, 842 | "execution_count": 31, 843 | "metadata": {}, 844 | "output_type": "execute_result" 845 | } 846 | ], 847 | "source": [ 848 | "fa.params.pop" 849 | ] 850 | }, 851 | { 852 | "cell_type": "markdown", 853 | "metadata": {}, 854 | "source": [ 855 | "Using dictionary syntax will return the proper value though." 856 | ] 857 | }, 858 | { 859 | "cell_type": "code", 860 | "execution_count": 33, 861 | "metadata": { 862 | "collapsed": false 863 | }, 864 | "outputs": [ 865 | { 866 | "data": { 867 | "text/plain": [ 868 | "'corn'" 869 | ] 870 | }, 871 | "execution_count": 33, 872 | "metadata": {}, 873 | "output_type": "execute_result" 874 | } 875 | ], 876 | "source": [ 877 | "fa.params['pop']" 878 | ] 879 | }, 880 | { 881 | "cell_type": "markdown", 882 | "metadata": {}, 883 | "source": [ 884 | "Parameters can also be set directly on the **CASAction** instance. " 885 | ] 886 | }, 887 | { 888 | "cell_type": "code", 889 | "execution_count": 35, 890 | "metadata": { 891 | "collapsed": false 892 | }, 893 | "outputs": [], 894 | "source": [ 895 | "fa = conn.Fetch()" 896 | ] 897 | }, 898 | { 899 | "cell_type": "code", 900 | "execution_count": 36, 901 | "metadata": { 902 | "collapsed": false 903 | }, 904 | "outputs": [ 905 | { 906 | "data": { 907 | "text/plain": [ 908 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'))" 909 | ] 910 | }, 911 | "execution_count": 36, 912 | "metadata": {}, 913 | "output_type": "execute_result" 914 | } 915 | ], 916 | "source": [ 917 | "fa.table.name = 'data.iris'\n", 918 | "fa.table.caslib = 'casuser'\n", 919 | "fa" 920 | ] 921 | }, 922 | { 923 | "cell_type": "code", 924 | "execution_count": 37, 925 | "metadata": { 926 | "collapsed": false 927 | }, 928 | "outputs": [ 929 | { 930 | "data": { 931 | "text/html": [ 932 | "
§ Fetch
\n", 933 | "
\n", 934 | "
\n", 935 | "\n", 936 | " \n", 937 | " \n", 938 | " \n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | " \n", 962 | " \n", 963 | " \n", 964 | " \n", 965 | " \n", 966 | " \n", 967 | " \n", 968 | " \n", 969 | " \n", 970 | " \n", 971 | " \n", 972 | " \n", 973 | " \n", 974 | " \n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
45.03.61.40.2setosa
\n", 989 | "
\n", 990 | "
\n", 991 | "
\n", 992 | "

elapsed 0.00336s · user 0.003s · mem 1.64MB

" 993 | ], 994 | "text/plain": [ 995 | "[Fetch]\n", 996 | "\n", 997 | " Selected Rows from Table DATA.IRIS\n", 998 | " \n", 999 | " sepal_length sepal_width petal_length petal_width species\n", 1000 | " 0 5.1 3.5 1.4 0.2 setosa\n", 1001 | " 1 4.9 3.0 1.4 0.2 setosa\n", 1002 | " 2 4.7 3.2 1.3 0.2 setosa\n", 1003 | " 3 4.6 3.1 1.5 0.2 setosa\n", 1004 | " 4 5.0 3.6 1.4 0.2 setosa\n", 1005 | "\n", 1006 | "+ Elapsed: 0.00336s, user: 0.003s, mem: 1.64mb" 1007 | ] 1008 | }, 1009 | "execution_count": 37, 1010 | "metadata": {}, 1011 | "output_type": "execute_result" 1012 | } 1013 | ], 1014 | "source": [ 1015 | "fa(to=5)" 1016 | ] 1017 | }, 1018 | { 1019 | "cell_type": "markdown", 1020 | "metadata": {}, 1021 | "source": [ 1022 | "### Retrieving and Removing Action Parameters" 1023 | ] 1024 | }, 1025 | { 1026 | "cell_type": "code", 1027 | "execution_count": 39, 1028 | "metadata": { 1029 | "collapsed": false 1030 | }, 1031 | "outputs": [ 1032 | { 1033 | "data": { 1034 | "text/plain": [ 1035 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 1036 | ] 1037 | }, 1038 | "execution_count": 39, 1039 | "metadata": {}, 1040 | "output_type": "execute_result" 1041 | } 1042 | ], 1043 | "source": [ 1044 | "fa = conn.Fetch(to=5, table=dict(name='data.iris', caslib='casuser'))\n", 1045 | "fa" 1046 | ] 1047 | }, 1048 | { 1049 | "cell_type": "code", 1050 | "execution_count": 40, 1051 | "metadata": { 1052 | "collapsed": false 1053 | }, 1054 | "outputs": [ 1055 | { 1056 | "data": { 1057 | "text/plain": [ 1058 | "5" 1059 | ] 1060 | }, 1061 | "execution_count": 40, 1062 | "metadata": {}, 1063 | "output_type": "execute_result" 1064 | } 1065 | ], 1066 | "source": [ 1067 | "fa.get_param('to')" 1068 | ] 1069 | }, 1070 | { 1071 | "cell_type": "code", 1072 | "execution_count": 41, 1073 | "metadata": { 1074 | "collapsed": false 1075 | }, 1076 | "outputs": [ 1077 | { 1078 | "data": { 1079 | "text/plain": [ 1080 | "{'table.name': 'data.iris', 'to': 5}" 1081 | ] 1082 | }, 1083 | "execution_count": 41, 1084 | "metadata": {}, 1085 | "output_type": "execute_result" 1086 | } 1087 | ], 1088 | "source": [ 1089 | "fa.get_params('to', 'table.name')" 1090 | ] 1091 | }, 1092 | { 1093 | "cell_type": "code", 1094 | "execution_count": 43, 1095 | "metadata": { 1096 | "collapsed": false 1097 | }, 1098 | "outputs": [ 1099 | { 1100 | "data": { 1101 | "text/plain": [ 1102 | "?.table.Fetch(table=dict(name='data.iris'))" 1103 | ] 1104 | }, 1105 | "execution_count": 43, 1106 | "metadata": {}, 1107 | "output_type": "execute_result" 1108 | } 1109 | ], 1110 | "source": [ 1111 | "fa.del_params('to', 'table.caslib')\n", 1112 | "fa" 1113 | ] 1114 | }, 1115 | { 1116 | "cell_type": "code", 1117 | "execution_count": 44, 1118 | "metadata": { 1119 | "collapsed": false 1120 | }, 1121 | "outputs": [ 1122 | { 1123 | "data": { 1124 | "text/plain": [ 1125 | "False" 1126 | ] 1127 | }, 1128 | "execution_count": 44, 1129 | "metadata": {}, 1130 | "output_type": "execute_result" 1131 | } 1132 | ], 1133 | "source": [ 1134 | "fa.has_param('table.caslib')" 1135 | ] 1136 | }, 1137 | { 1138 | "cell_type": "code", 1139 | "execution_count": 45, 1140 | "metadata": { 1141 | "collapsed": false 1142 | }, 1143 | "outputs": [ 1144 | { 1145 | "data": { 1146 | "text/plain": [ 1147 | "True" 1148 | ] 1149 | }, 1150 | "execution_count": 45, 1151 | "metadata": {}, 1152 | "output_type": "execute_result" 1153 | } 1154 | ], 1155 | "source": [ 1156 | "fa.has_param('table.name')" 1157 | ] 1158 | }, 1159 | { 1160 | "cell_type": "code", 1161 | "execution_count": 46, 1162 | "metadata": { 1163 | "collapsed": false 1164 | }, 1165 | "outputs": [ 1166 | { 1167 | "data": { 1168 | "text/plain": [ 1169 | "False" 1170 | ] 1171 | }, 1172 | "execution_count": 46, 1173 | "metadata": {}, 1174 | "output_type": "execute_result" 1175 | } 1176 | ], 1177 | "source": [ 1178 | "fa.has_param('table.name', 'to')" 1179 | ] 1180 | }, 1181 | { 1182 | "cell_type": "markdown", 1183 | "metadata": {}, 1184 | "source": [ 1185 | "Retrieve parameter values using attributes." 1186 | ] 1187 | }, 1188 | { 1189 | "cell_type": "code", 1190 | "execution_count": 47, 1191 | "metadata": { 1192 | "collapsed": false 1193 | }, 1194 | "outputs": [ 1195 | { 1196 | "data": { 1197 | "text/plain": [ 1198 | "?.table.Fetch(table=dict(caslib='casuser', name='data.iris'), to=5)" 1199 | ] 1200 | }, 1201 | "execution_count": 47, 1202 | "metadata": {}, 1203 | "output_type": "execute_result" 1204 | } 1205 | ], 1206 | "source": [ 1207 | "fa = conn.Fetch(to=5, table=dict(name='data.iris', caslib='casuser'))\n", 1208 | "fa" 1209 | ] 1210 | }, 1211 | { 1212 | "cell_type": "code", 1213 | "execution_count": 48, 1214 | "metadata": { 1215 | "collapsed": false 1216 | }, 1217 | "outputs": [ 1218 | { 1219 | "data": { 1220 | "text/plain": [ 1221 | "'data.iris'" 1222 | ] 1223 | }, 1224 | "execution_count": 48, 1225 | "metadata": {}, 1226 | "output_type": "execute_result" 1227 | } 1228 | ], 1229 | "source": [ 1230 | "fa.table.name" 1231 | ] 1232 | }, 1233 | { 1234 | "cell_type": "code", 1235 | "execution_count": 49, 1236 | "metadata": { 1237 | "collapsed": false 1238 | }, 1239 | "outputs": [ 1240 | { 1241 | "data": { 1242 | "text/plain": [ 1243 | "{'caslib': 'casuser', 'name': 'data.iris'}" 1244 | ] 1245 | }, 1246 | "execution_count": 49, 1247 | "metadata": {}, 1248 | "output_type": "execute_result" 1249 | } 1250 | ], 1251 | "source": [ 1252 | "fa.table" 1253 | ] 1254 | }, 1255 | { 1256 | "cell_type": "code", 1257 | "execution_count": 50, 1258 | "metadata": { 1259 | "collapsed": true 1260 | }, 1261 | "outputs": [], 1262 | "source": [ 1263 | "del fa.table.caslib" 1264 | ] 1265 | }, 1266 | { 1267 | "cell_type": "code", 1268 | "execution_count": 51, 1269 | "metadata": { 1270 | "collapsed": false 1271 | }, 1272 | "outputs": [ 1273 | { 1274 | "data": { 1275 | "text/plain": [ 1276 | "{'name': 'data.iris'}" 1277 | ] 1278 | }, 1279 | "execution_count": 51, 1280 | "metadata": {}, 1281 | "output_type": "execute_result" 1282 | } 1283 | ], 1284 | "source": [ 1285 | "fa.table" 1286 | ] 1287 | }, 1288 | { 1289 | "cell_type": "markdown", 1290 | "metadata": {}, 1291 | "source": [ 1292 | "## First Steps with the CASTable Object" 1293 | ] 1294 | }, 1295 | { 1296 | "cell_type": "code", 1297 | "execution_count": 52, 1298 | "metadata": { 1299 | "collapsed": false 1300 | }, 1301 | "outputs": [ 1302 | { 1303 | "name": "stderr", 1304 | "output_type": "stream", 1305 | "text": [ 1306 | "ERROR: The table DATA.IRIS already exists in caslib CASUSER(username).\n", 1307 | "ERROR: The action stopped due to errors.\n" 1308 | ] 1309 | }, 1310 | { 1311 | "data": { 1312 | "text/html": [ 1313 | "
§ caslib
\n", 1314 | "
\n", 1315 | "
CASUSER(username)
\n", 1316 | "
\n", 1317 | "

§ tableName
\n", 1318 | "
\n", 1319 | "
DATA.IRIS
\n", 1320 | "
\n", 1321 | "

§ casTable
\n", 1322 | "
\n", 1323 | "
CASTable('DATA.IRIS', caslib='CASUSER(username)')
\n", 1324 | "
\n", 1325 | "
\n", 1326 | "

elapsed 0.000472s · mem 0.123MB

" 1327 | ], 1328 | "text/plain": [ 1329 | "[caslib]\n", 1330 | "\n", 1331 | " 'CASUSER(username)'\n", 1332 | "\n", 1333 | "[tableName]\n", 1334 | "\n", 1335 | " 'DATA.IRIS'\n", 1336 | "\n", 1337 | "[casTable]\n", 1338 | "\n", 1339 | " CASTable('DATA.IRIS', caslib='CASUSER(username)')\n", 1340 | "\n", 1341 | "+ Elapsed: 0.000472s, mem: 0.123mb" 1342 | ] 1343 | }, 1344 | "execution_count": 52, 1345 | "metadata": {}, 1346 | "output_type": "execute_result" 1347 | } 1348 | ], 1349 | "source": [ 1350 | "out = conn.loadtable('data/iris.csv', caslib='casuser')\n", 1351 | "out" 1352 | ] 1353 | }, 1354 | { 1355 | "cell_type": "code", 1356 | "execution_count": 53, 1357 | "metadata": { 1358 | "collapsed": false 1359 | }, 1360 | "outputs": [ 1361 | { 1362 | "data": { 1363 | "text/plain": [ 1364 | "'DATA.IRIS'" 1365 | ] 1366 | }, 1367 | "execution_count": 53, 1368 | "metadata": {}, 1369 | "output_type": "execute_result" 1370 | } 1371 | ], 1372 | "source": [ 1373 | "out['tableName']" 1374 | ] 1375 | }, 1376 | { 1377 | "cell_type": "code", 1378 | "execution_count": 54, 1379 | "metadata": { 1380 | "collapsed": false 1381 | }, 1382 | "outputs": [ 1383 | { 1384 | "data": { 1385 | "text/plain": [ 1386 | "'CASUSER(username)'" 1387 | ] 1388 | }, 1389 | "execution_count": 54, 1390 | "metadata": {}, 1391 | "output_type": "execute_result" 1392 | } 1393 | ], 1394 | "source": [ 1395 | "out['caslib']" 1396 | ] 1397 | }, 1398 | { 1399 | "cell_type": "code", 1400 | "execution_count": 55, 1401 | "metadata": { 1402 | "collapsed": false 1403 | }, 1404 | "outputs": [ 1405 | { 1406 | "data": { 1407 | "text/plain": [ 1408 | "CASTable('DATA.IRIS', caslib='CASUSER(username)')" 1409 | ] 1410 | }, 1411 | "execution_count": 55, 1412 | "metadata": {}, 1413 | "output_type": "execute_result" 1414 | } 1415 | ], 1416 | "source": [ 1417 | "out['casTable']" 1418 | ] 1419 | }, 1420 | { 1421 | "cell_type": "code", 1422 | "execution_count": 56, 1423 | "metadata": { 1424 | "collapsed": false 1425 | }, 1426 | "outputs": [ 1427 | { 1428 | "data": { 1429 | "text/plain": [ 1430 | "CASTable('DATA.IRIS', caslib='CASUSER(username)')" 1431 | ] 1432 | }, 1433 | "execution_count": 56, 1434 | "metadata": {}, 1435 | "output_type": "execute_result" 1436 | } 1437 | ], 1438 | "source": [ 1439 | "out.casTable" 1440 | ] 1441 | }, 1442 | { 1443 | "cell_type": "code", 1444 | "execution_count": 57, 1445 | "metadata": { 1446 | "collapsed": false 1447 | }, 1448 | "outputs": [ 1449 | { 1450 | "data": { 1451 | "text/html": [ 1452 | "
§ TableInfo
\n", 1453 | "
\n", 1454 | "
\n", 1455 | "\n", 1456 | " \n", 1457 | " \n", 1458 | " \n", 1459 | " \n", 1460 | " \n", 1461 | " \n", 1462 | " \n", 1463 | " \n", 1464 | " \n", 1465 | " \n", 1466 | " \n", 1467 | " \n", 1468 | " \n", 1469 | " \n", 1470 | " \n", 1471 | " \n", 1472 | " \n", 1473 | " \n", 1474 | " \n", 1475 | " \n", 1476 | " \n", 1477 | " \n", 1478 | " \n", 1479 | " \n", 1480 | " \n", 1481 | " \n", 1482 | " \n", 1483 | " \n", 1484 | " \n", 1485 | " \n", 1486 | " \n", 1487 | " \n", 1488 | " \n", 1489 | " \n", 1490 | " \n", 1491 | " \n", 1492 | " \n", 1493 | " \n", 1494 | " \n", 1495 | " \n", 1496 | " \n", 1497 | " \n", 1498 | " \n", 1499 | " \n", 1500 | "
NameRowsColumnsEncodingCreateTimeFormattedModTimeFormattedJavaCharSetCreateTimeModTimeGlobalRepeatedViewSourceNameSourceCaslibCompressedCreatorModifier
0DATA.IRIS1505utf-803Nov2016:15:28:5703Nov2016:15:28:57UTF81.793806e+091.793806e+09000data/iris.csvCASUSER(username)0username
\n", 1501 | "
\n", 1502 | "
\n", 1503 | "
\n", 1504 | "

elapsed 0.000939s · sys 0.001s · mem 0.106MB

" 1505 | ], 1506 | "text/plain": [ 1507 | "[TableInfo]\n", 1508 | "\n", 1509 | " Name Rows Columns Encoding CreateTimeFormatted ModTimeFormatted \\\n", 1510 | " 0 DATA.IRIS 150 5 utf-8 03Nov2016:15:28:57 03Nov2016:15:28:57 \n", 1511 | " \n", 1512 | " JavaCharSet CreateTime ModTime Global Repeated View \\\n", 1513 | " 0 UTF8 1.793806e+09 1.793806e+09 0 0 0 \n", 1514 | " \n", 1515 | " SourceName SourceCaslib Compressed Creator Modifier \n", 1516 | " 0 data/iris.csv CASUSER(username) 0 username \n", 1517 | "\n", 1518 | "+ Elapsed: 0.000939s, sys: 0.001s, mem: 0.106mb" 1519 | ] 1520 | }, 1521 | "execution_count": 57, 1522 | "metadata": {}, 1523 | "output_type": "execute_result" 1524 | } 1525 | ], 1526 | "source": [ 1527 | "out.casTable.tableinfo()" 1528 | ] 1529 | }, 1530 | { 1531 | "cell_type": "code", 1532 | "execution_count": 58, 1533 | "metadata": { 1534 | "collapsed": false 1535 | }, 1536 | "outputs": [ 1537 | { 1538 | "data": { 1539 | "text/html": [ 1540 | "
§ ColumnInfo
\n", 1541 | "
\n", 1542 | "
\n", 1543 | "\n", 1544 | " \n", 1545 | " \n", 1546 | " \n", 1547 | " \n", 1548 | " \n", 1549 | " \n", 1550 | " \n", 1551 | " \n", 1552 | " \n", 1553 | " \n", 1554 | " \n", 1555 | " \n", 1556 | " \n", 1557 | " \n", 1558 | " \n", 1559 | " \n", 1560 | " \n", 1561 | " \n", 1562 | " \n", 1563 | " \n", 1564 | " \n", 1565 | " \n", 1566 | " \n", 1567 | " \n", 1568 | " \n", 1569 | " \n", 1570 | " \n", 1571 | " \n", 1572 | " \n", 1573 | " \n", 1574 | " \n", 1575 | " \n", 1576 | " \n", 1577 | " \n", 1578 | " \n", 1579 | " \n", 1580 | " \n", 1581 | " \n", 1582 | " \n", 1583 | " \n", 1584 | " \n", 1585 | " \n", 1586 | " \n", 1587 | " \n", 1588 | " \n", 1589 | " \n", 1590 | " \n", 1591 | " \n", 1592 | " \n", 1593 | " \n", 1594 | " \n", 1595 | " \n", 1596 | " \n", 1597 | " \n", 1598 | " \n", 1599 | " \n", 1600 | " \n", 1601 | " \n", 1602 | " \n", 1603 | " \n", 1604 | " \n", 1605 | " \n", 1606 | " \n", 1607 | " \n", 1608 | "
ColumnIDTypeRawLengthFormattedLengthNFLNFD
0sepal_length1double81200
1sepal_width2double81200
2petal_length3double81200
3petal_width4double81200
4species5varchar101000
\n", 1609 | "
\n", 1610 | "
\n", 1611 | "
\n", 1612 | "

elapsed 0.000666s · user 0.001s · mem 0.169MB

" 1613 | ], 1614 | "text/plain": [ 1615 | "[ColumnInfo]\n", 1616 | "\n", 1617 | " Column ID Type RawLength FormattedLength NFL NFD\n", 1618 | " 0 sepal_length 1 double 8 12 0 0\n", 1619 | " 1 sepal_width 2 double 8 12 0 0\n", 1620 | " 2 petal_length 3 double 8 12 0 0\n", 1621 | " 3 petal_width 4 double 8 12 0 0\n", 1622 | " 4 species 5 varchar 10 10 0 0\n", 1623 | "\n", 1624 | "+ Elapsed: 0.000666s, user: 0.001s, mem: 0.169mb" 1625 | ] 1626 | }, 1627 | "execution_count": 58, 1628 | "metadata": {}, 1629 | "output_type": "execute_result" 1630 | } 1631 | ], 1632 | "source": [ 1633 | "out.casTable.columninfo()" 1634 | ] 1635 | }, 1636 | { 1637 | "cell_type": "code", 1638 | "execution_count": 59, 1639 | "metadata": { 1640 | "collapsed": false 1641 | }, 1642 | "outputs": [ 1643 | { 1644 | "data": { 1645 | "text/html": [ 1646 | "
§ Fetch
\n", 1647 | "
\n", 1648 | "
\n", 1649 | "\n", 1650 | " \n", 1651 | " \n", 1652 | " \n", 1653 | " \n", 1654 | " \n", 1655 | " \n", 1656 | " \n", 1657 | " \n", 1658 | " \n", 1659 | " \n", 1660 | " \n", 1661 | " \n", 1662 | " \n", 1663 | " \n", 1664 | " \n", 1665 | " \n", 1666 | " \n", 1667 | " \n", 1668 | " \n", 1669 | " \n", 1670 | " \n", 1671 | " \n", 1672 | " \n", 1673 | " \n", 1674 | " \n", 1675 | " \n", 1676 | " \n", 1677 | " \n", 1678 | " \n", 1679 | " \n", 1680 | " \n", 1681 | " \n", 1682 | " \n", 1683 | " \n", 1684 | " \n", 1685 | " \n", 1686 | " \n", 1687 | " \n", 1688 | " \n", 1689 | " \n", 1690 | " \n", 1691 | " \n", 1692 | " \n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | "
Selected Rows from Table DATA.IRIS
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
45.03.61.40.2setosa
\n", 1703 | "
\n", 1704 | "
\n", 1705 | "
\n", 1706 | "

elapsed 0.00335s · user 0.002s · sys 0.001s · mem 1.64MB

" 1707 | ], 1708 | "text/plain": [ 1709 | "[Fetch]\n", 1710 | "\n", 1711 | " Selected Rows from Table DATA.IRIS\n", 1712 | " \n", 1713 | " sepal_length sepal_width petal_length petal_width species\n", 1714 | " 0 5.1 3.5 1.4 0.2 setosa\n", 1715 | " 1 4.9 3.0 1.4 0.2 setosa\n", 1716 | " 2 4.7 3.2 1.3 0.2 setosa\n", 1717 | " 3 4.6 3.1 1.5 0.2 setosa\n", 1718 | " 4 5.0 3.6 1.4 0.2 setosa\n", 1719 | "\n", 1720 | "+ Elapsed: 0.00335s, user: 0.002s, sys: 0.001s, mem: 1.64mb" 1721 | ] 1722 | }, 1723 | "execution_count": 59, 1724 | "metadata": {}, 1725 | "output_type": "execute_result" 1726 | } 1727 | ], 1728 | "source": [ 1729 | "out.casTable.fetch(to=5)" 1730 | ] 1731 | }, 1732 | { 1733 | "cell_type": "code", 1734 | "execution_count": 60, 1735 | "metadata": { 1736 | "collapsed": false 1737 | }, 1738 | "outputs": [ 1739 | { 1740 | "data": { 1741 | "text/html": [ 1742 | "
§ Summary
\n", 1743 | "
\n", 1744 | "
\n", 1745 | "\n", 1746 | " \n", 1747 | " \n", 1748 | " \n", 1749 | " \n", 1750 | " \n", 1751 | " \n", 1752 | " \n", 1753 | " \n", 1754 | " \n", 1755 | " \n", 1756 | " \n", 1757 | " \n", 1758 | " \n", 1759 | " \n", 1760 | " \n", 1761 | " \n", 1762 | " \n", 1763 | " \n", 1764 | " \n", 1765 | " \n", 1766 | " \n", 1767 | " \n", 1768 | " \n", 1769 | " \n", 1770 | " \n", 1771 | " \n", 1772 | " \n", 1773 | " \n", 1774 | " \n", 1775 | " \n", 1776 | " \n", 1777 | " \n", 1778 | " \n", 1779 | " \n", 1780 | " \n", 1781 | " \n", 1782 | " \n", 1783 | " \n", 1784 | " \n", 1785 | " \n", 1786 | " \n", 1787 | " \n", 1788 | " \n", 1789 | " \n", 1790 | " \n", 1791 | " \n", 1792 | " \n", 1793 | " \n", 1794 | " \n", 1795 | " \n", 1796 | " \n", 1797 | " \n", 1798 | " \n", 1799 | " \n", 1800 | " \n", 1801 | " \n", 1802 | " \n", 1803 | " \n", 1804 | " \n", 1805 | " \n", 1806 | " \n", 1807 | " \n", 1808 | " \n", 1809 | " \n", 1810 | " \n", 1811 | " \n", 1812 | " \n", 1813 | " \n", 1814 | " \n", 1815 | " \n", 1816 | " \n", 1817 | " \n", 1818 | " \n", 1819 | " \n", 1820 | " \n", 1821 | " \n", 1822 | " \n", 1823 | " \n", 1824 | " \n", 1825 | " \n", 1826 | " \n", 1827 | " \n", 1828 | " \n", 1829 | " \n", 1830 | " \n", 1831 | " \n", 1832 | " \n", 1833 | " \n", 1834 | " \n", 1835 | " \n", 1836 | " \n", 1837 | " \n", 1838 | " \n", 1839 | " \n", 1840 | "
Descriptive Statistics for DATA.IRIS
ColumnMinMaxNNMissMeanSumStdStdErrVarUSSCSSCVTValueProbT
0sepal_length4.37.9150.00.05.843333876.50.8280660.0676110.6856945223.85102.16833314.17112686.4253753.331256e-129
1sepal_width2.04.4150.00.03.054000458.10.4335940.0354030.1880041427.0528.01260014.19758786.2642974.374977e-129
2petal_length1.06.9150.00.03.758667563.81.7644200.1440643.1131792583.00463.86373346.94272126.0901981.994305e-57
3petal_width0.12.5150.00.01.198667179.80.7631610.0623120.582414302.3086.77973363.66747019.2365883.209704e-42
\n", 1841 | "
\n", 1842 | "
\n", 1843 | "
\n", 1844 | "

elapsed 0.0249s · user 0.025s · sys 0.005s · mem 1.74MB

" 1845 | ], 1846 | "text/plain": [ 1847 | "[Summary]\n", 1848 | "\n", 1849 | " Descriptive Statistics for DATA.IRIS\n", 1850 | " \n", 1851 | " Column Min Max N NMiss Mean Sum Std StdErr \\\n", 1852 | " 0 sepal_length 4.3 7.9 150.0 0.0 5.843333 876.5 0.828066 0.067611 \n", 1853 | " 1 sepal_width 2.0 4.4 150.0 0.0 3.054000 458.1 0.433594 0.035403 \n", 1854 | " 2 petal_length 1.0 6.9 150.0 0.0 3.758667 563.8 1.764420 0.144064 \n", 1855 | " 3 petal_width 0.1 2.5 150.0 0.0 1.198667 179.8 0.763161 0.062312 \n", 1856 | " \n", 1857 | " Var USS CSS CV TValue ProbT \n", 1858 | " 0 0.685694 5223.85 102.168333 14.171126 86.425375 3.331256e-129 \n", 1859 | " 1 0.188004 1427.05 28.012600 14.197587 86.264297 4.374977e-129 \n", 1860 | " 2 3.113179 2583.00 463.863733 46.942721 26.090198 1.994305e-57 \n", 1861 | " 3 0.582414 302.30 86.779733 63.667470 19.236588 3.209704e-42 \n", 1862 | "\n", 1863 | "+ Elapsed: 0.0249s, user: 0.025s, sys: 0.005s, mem: 1.74mb" 1864 | ] 1865 | }, 1866 | "execution_count": 60, 1867 | "metadata": {}, 1868 | "output_type": "execute_result" 1869 | } 1870 | ], 1871 | "source": [ 1872 | "out.casTable.summary()" 1873 | ] 1874 | }, 1875 | { 1876 | "cell_type": "code", 1877 | "execution_count": 61, 1878 | "metadata": { 1879 | "collapsed": false 1880 | }, 1881 | "outputs": [ 1882 | { 1883 | "data": { 1884 | "text/html": [ 1885 | "
§ CorrSimple
\n", 1886 | "
\n", 1887 | "
\n", 1888 | "\n", 1889 | " \n", 1890 | " \n", 1891 | " \n", 1892 | " \n", 1893 | " \n", 1894 | " \n", 1895 | " \n", 1896 | " \n", 1897 | " \n", 1898 | " \n", 1899 | " \n", 1900 | " \n", 1901 | " \n", 1902 | " \n", 1903 | " \n", 1904 | " \n", 1905 | " \n", 1906 | " \n", 1907 | " \n", 1908 | " \n", 1909 | " \n", 1910 | " \n", 1911 | " \n", 1912 | " \n", 1913 | " \n", 1914 | " \n", 1915 | " \n", 1916 | " \n", 1917 | " \n", 1918 | " \n", 1919 | " \n", 1920 | " \n", 1921 | " \n", 1922 | " \n", 1923 | " \n", 1924 | " \n", 1925 | " \n", 1926 | " \n", 1927 | " \n", 1928 | " \n", 1929 | " \n", 1930 | " \n", 1931 | " \n", 1932 | " \n", 1933 | " \n", 1934 | " \n", 1935 | " \n", 1936 | " \n", 1937 | " \n", 1938 | " \n", 1939 | " \n", 1940 | " \n", 1941 | " \n", 1942 | " \n", 1943 | "
Summary Statistics in Correlation Analysis for DATA.IRIS
VariableNMeanSumStdDevMinimumMaximum
0sepal_length150.05.843333876.50.8280664.37.9
1sepal_width150.03.054000458.10.4335942.04.4
2petal_length150.03.758667563.81.7644201.06.9
3petal_width150.01.198667179.80.7631610.12.5
\n", 1944 | "
\n", 1945 | "
\n", 1946 | "

§ Correlation
\n", 1947 | "
\n", 1948 | "
\n", 1949 | "\n", 1950 | " \n", 1951 | " \n", 1952 | " \n", 1953 | " \n", 1954 | " \n", 1955 | " \n", 1956 | " \n", 1957 | " \n", 1958 | " \n", 1959 | " \n", 1960 | " \n", 1961 | " \n", 1962 | " \n", 1963 | " \n", 1964 | " \n", 1965 | " \n", 1966 | " \n", 1967 | " \n", 1968 | " \n", 1969 | " \n", 1970 | " \n", 1971 | " \n", 1972 | " \n", 1973 | " \n", 1974 | " \n", 1975 | " \n", 1976 | " \n", 1977 | " \n", 1978 | " \n", 1979 | " \n", 1980 | " \n", 1981 | " \n", 1982 | " \n", 1983 | " \n", 1984 | " \n", 1985 | " \n", 1986 | " \n", 1987 | " \n", 1988 | " \n", 1989 | " \n", 1990 | " \n", 1991 | " \n", 1992 | " \n", 1993 | " \n", 1994 | "
Pearson Correlation Coefficients for DATA.IRIS
Variablesepal_lengthsepal_widthpetal_lengthpetal_width
0sepal_length1.000000-0.1093690.8717540.817954
1sepal_width-0.1093691.000000-0.420516-0.356544
2petal_length0.871754-0.4205161.0000000.962757
3petal_width0.817954-0.3565440.9627571.000000
\n", 1995 | "
\n", 1996 | "
\n", 1997 | "
\n", 1998 | "

elapsed 0.00596s · user 0.005s · sys 0.004s · mem 1.73MB

" 1999 | ], 2000 | "text/plain": [ 2001 | "[CorrSimple]\n", 2002 | "\n", 2003 | " Summary Statistics in Correlation Analysis for DATA.IRIS\n", 2004 | " \n", 2005 | " Variable N Mean Sum StdDev Minimum Maximum\n", 2006 | " 0 sepal_length 150.0 5.843333 876.5 0.828066 4.3 7.9\n", 2007 | " 1 sepal_width 150.0 3.054000 458.1 0.433594 2.0 4.4\n", 2008 | " 2 petal_length 150.0 3.758667 563.8 1.764420 1.0 6.9\n", 2009 | " 3 petal_width 150.0 1.198667 179.8 0.763161 0.1 2.5\n", 2010 | "\n", 2011 | "[Correlation]\n", 2012 | "\n", 2013 | " Pearson Correlation Coefficients for DATA.IRIS\n", 2014 | " \n", 2015 | " Variable sepal_length sepal_width petal_length petal_width\n", 2016 | " 0 sepal_length 1.000000 -0.109369 0.871754 0.817954\n", 2017 | " 1 sepal_width -0.109369 1.000000 -0.420516 -0.356544\n", 2018 | " 2 petal_length 0.871754 -0.420516 1.000000 0.962757\n", 2019 | " 3 petal_width 0.817954 -0.356544 0.962757 1.000000\n", 2020 | "\n", 2021 | "+ Elapsed: 0.00596s, user: 0.005s, sys: 0.004s, mem: 1.73mb" 2022 | ] 2023 | }, 2024 | "execution_count": 61, 2025 | "metadata": {}, 2026 | "output_type": "execute_result" 2027 | } 2028 | ], 2029 | "source": [ 2030 | "out.casTable.correlation()" 2031 | ] 2032 | }, 2033 | { 2034 | "cell_type": "code", 2035 | "execution_count": 62, 2036 | "metadata": { 2037 | "collapsed": false 2038 | }, 2039 | "outputs": [ 2040 | { 2041 | "data": { 2042 | "text/html": [ 2043 | "
§ userInfo
\n", 2044 | "
\n", 2045 | "
{'anonymous': False, 'providedName': 'username', 'hostAccount': True, 'userId': 'username', 'groups': ['users'], 'providerName': 'Active Directory', 'uniqueId': 'username'}
\n", 2046 | "
\n", 2047 | "
\n", 2048 | "

elapsed 0.000302s · mem 0.0656MB

" 2049 | ], 2050 | "text/plain": [ 2051 | "[userInfo]\n", 2052 | "\n", 2053 | " {'anonymous': False,\n", 2054 | " 'groups': ['users'],\n", 2055 | " 'hostAccount': True,\n", 2056 | " 'providedName': 'username',\n", 2057 | " 'providerName': 'Active Directory',\n", 2058 | " 'uniqueId': 'username',\n", 2059 | " 'userId': 'username'}\n", 2060 | "\n", 2061 | "+ Elapsed: 0.000302s, mem: 0.0656mb" 2062 | ] 2063 | }, 2064 | "execution_count": 62, 2065 | "metadata": {}, 2066 | "output_type": "execute_result" 2067 | } 2068 | ], 2069 | "source": [ 2070 | "out.casTable.userinfo()" 2071 | ] 2072 | }, 2073 | { 2074 | "cell_type": "markdown", 2075 | "metadata": {}, 2076 | "source": [ 2077 | "Even some Pandas DataFrame methods and attributes work on **CASTable** objects. Here is a small sample." 2078 | ] 2079 | }, 2080 | { 2081 | "cell_type": "code", 2082 | "execution_count": 63, 2083 | "metadata": { 2084 | "collapsed": false 2085 | }, 2086 | "outputs": [ 2087 | { 2088 | "data": { 2089 | "text/plain": [ 2090 | "Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',\n", 2091 | " 'species'],\n", 2092 | " dtype='object')" 2093 | ] 2094 | }, 2095 | "execution_count": 63, 2096 | "metadata": {}, 2097 | "output_type": "execute_result" 2098 | } 2099 | ], 2100 | "source": [ 2101 | "out.casTable.columns" 2102 | ] 2103 | }, 2104 | { 2105 | "cell_type": "code", 2106 | "execution_count": 64, 2107 | "metadata": { 2108 | "collapsed": false 2109 | }, 2110 | "outputs": [ 2111 | { 2112 | "data": { 2113 | "text/plain": [ 2114 | "sepal_length double\n", 2115 | "sepal_width double\n", 2116 | "petal_length double\n", 2117 | "petal_width double\n", 2118 | "species varchar\n", 2119 | "dtype: object" 2120 | ] 2121 | }, 2122 | "execution_count": 64, 2123 | "metadata": {}, 2124 | "output_type": "execute_result" 2125 | } 2126 | ], 2127 | "source": [ 2128 | "out.casTable.dtypes" 2129 | ] 2130 | }, 2131 | { 2132 | "cell_type": "code", 2133 | "execution_count": 65, 2134 | "metadata": { 2135 | "collapsed": false 2136 | }, 2137 | "outputs": [ 2138 | { 2139 | "name": "stdout", 2140 | "output_type": "stream", 2141 | "text": [ 2142 | "CASTable('DATA.IRIS', caslib='CASUSER(username)')\n", 2143 | "Data columns (total 5 columns):\n", 2144 | " N Miss Type\n", 2145 | "sepal_length 150 False double\n", 2146 | "sepal_width 150 False double\n", 2147 | "petal_length 150 False double\n", 2148 | "petal_width 150 False double\n", 2149 | "species 150 False varchar\n", 2150 | "dtypes: double(4), varchar(1)\n", 2151 | "data size: 8450\n", 2152 | "vardata size: 1250\n", 2153 | "memory usage: 8536\n" 2154 | ] 2155 | } 2156 | ], 2157 | "source": [ 2158 | "out.casTable.info()" 2159 | ] 2160 | }, 2161 | { 2162 | "cell_type": "code", 2163 | "execution_count": 67, 2164 | "metadata": { 2165 | "collapsed": false 2166 | }, 2167 | "outputs": [ 2168 | { 2169 | "data": { 2170 | "text/html": [ 2171 | "
\n", 2172 | "\n", 2173 | " \n", 2174 | " \n", 2175 | " \n", 2176 | " \n", 2177 | " \n", 2178 | " \n", 2179 | " \n", 2180 | " \n", 2181 | " \n", 2182 | " \n", 2183 | " \n", 2184 | " \n", 2185 | " \n", 2186 | " \n", 2187 | " \n", 2188 | " \n", 2189 | " \n", 2190 | " \n", 2191 | " \n", 2192 | " \n", 2193 | " \n", 2194 | " \n", 2195 | " \n", 2196 | " \n", 2197 | " \n", 2198 | " \n", 2199 | " \n", 2200 | " \n", 2201 | " \n", 2202 | " \n", 2203 | " \n", 2204 | " \n", 2205 | " \n", 2206 | " \n", 2207 | " \n", 2208 | " \n", 2209 | " \n", 2210 | " \n", 2211 | " \n", 2212 | " \n", 2213 | " \n", 2214 | " \n", 2215 | " \n", 2216 | " \n", 2217 | " \n", 2218 | " \n", 2219 | " \n", 2220 | " \n", 2221 | " \n", 2222 | " \n", 2223 | " \n", 2224 | " \n", 2225 | " \n", 2226 | " \n", 2227 | " \n", 2228 | " \n", 2229 | " \n", 2230 | " \n", 2231 | " \n", 2232 | " \n", 2233 | " \n", 2234 | " \n", 2235 | " \n", 2236 | " \n", 2237 | " \n", 2238 | " \n", 2239 | " \n", 2240 | " \n", 2241 | " \n", 2242 | " \n", 2243 | " \n", 2244 | " \n", 2245 | " \n", 2246 | " \n", 2247 | " \n", 2248 | " \n", 2249 | " \n", 2250 | " \n", 2251 | " \n", 2252 | " \n", 2253 | " \n", 2254 | " \n", 2255 | " \n", 2256 | " \n", 2257 | " \n", 2258 | " \n", 2259 | " \n", 2260 | " \n", 2261 | " \n", 2262 | " \n", 2263 | " \n", 2264 | " \n", 2265 | " \n", 2266 | " \n", 2267 | " \n", 2268 | " \n", 2269 | " \n", 2270 | " \n", 2271 | " \n", 2272 | " \n", 2273 | "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
count150150150150150
unique352343223
top531.50.2virginica
freq1026142850
mean5.843333.0543.758671.19867NaN
std0.8280660.4335941.764420.763161NaN
min4.3210.1setosa
40%5.633.91.15NaN
50%5.834.351.3NaN
80%6.553.45.351.9NaN
max7.94.46.92.5virginica
\n", 2274 | "
" 2275 | ], 2276 | "text/plain": [ 2277 | " sepal_length sepal_width petal_length petal_width species\n", 2278 | "count 150 150 150 150 150\n", 2279 | "unique 35 23 43 22 3\n", 2280 | "top 5 3 1.5 0.2 virginica\n", 2281 | "freq 10 26 14 28 50\n", 2282 | "mean 5.84333 3.054 3.75867 1.19867 NaN\n", 2283 | "std 0.828066 0.433594 1.76442 0.763161 NaN\n", 2284 | "min 4.3 2 1 0.1 setosa\n", 2285 | "40% 5.6 3 3.9 1.15 NaN\n", 2286 | "50% 5.8 3 4.35 1.3 NaN\n", 2287 | "80% 6.55 3.4 5.35 1.9 NaN\n", 2288 | "max 7.9 4.4 6.9 2.5 virginica" 2289 | ] 2290 | }, 2291 | "execution_count": 67, 2292 | "metadata": {}, 2293 | "output_type": "execute_result" 2294 | } 2295 | ], 2296 | "source": [ 2297 | "out.casTable.describe(include=['all'], percentiles=[.4, .8])" 2298 | ] 2299 | }, 2300 | { 2301 | "cell_type": "markdown", 2302 | "metadata": {}, 2303 | "source": [ 2304 | "### Manually Creating a CASTable Object" 2305 | ] 2306 | }, 2307 | { 2308 | "cell_type": "code", 2309 | "execution_count": 68, 2310 | "metadata": { 2311 | "collapsed": false 2312 | }, 2313 | "outputs": [ 2314 | { 2315 | "data": { 2316 | "text/plain": [ 2317 | "CASTable('data.iris', caslib='casuser')" 2318 | ] 2319 | }, 2320 | "execution_count": 68, 2321 | "metadata": {}, 2322 | "output_type": "execute_result" 2323 | } 2324 | ], 2325 | "source": [ 2326 | "newtbl = conn.CASTable('data.iris', caslib='casuser')\n", 2327 | "newtbl" 2328 | ] 2329 | }, 2330 | { 2331 | "cell_type": "code", 2332 | "execution_count": 69, 2333 | "metadata": { 2334 | "collapsed": false 2335 | }, 2336 | "outputs": [ 2337 | { 2338 | "data": { 2339 | "text/html": [ 2340 | "
§ ColumnInfo
\n", 2341 | "
\n", 2342 | "
\n", 2343 | "\n", 2344 | " \n", 2345 | " \n", 2346 | " \n", 2347 | " \n", 2348 | " \n", 2349 | " \n", 2350 | " \n", 2351 | " \n", 2352 | " \n", 2353 | " \n", 2354 | " \n", 2355 | " \n", 2356 | " \n", 2357 | " \n", 2358 | " \n", 2359 | " \n", 2360 | " \n", 2361 | " \n", 2362 | " \n", 2363 | " \n", 2364 | " \n", 2365 | " \n", 2366 | " \n", 2367 | " \n", 2368 | " \n", 2369 | " \n", 2370 | " \n", 2371 | " \n", 2372 | " \n", 2373 | " \n", 2374 | " \n", 2375 | " \n", 2376 | " \n", 2377 | " \n", 2378 | " \n", 2379 | " \n", 2380 | " \n", 2381 | " \n", 2382 | " \n", 2383 | " \n", 2384 | " \n", 2385 | " \n", 2386 | " \n", 2387 | " \n", 2388 | " \n", 2389 | " \n", 2390 | " \n", 2391 | " \n", 2392 | " \n", 2393 | " \n", 2394 | " \n", 2395 | " \n", 2396 | " \n", 2397 | " \n", 2398 | " \n", 2399 | " \n", 2400 | " \n", 2401 | " \n", 2402 | " \n", 2403 | " \n", 2404 | " \n", 2405 | " \n", 2406 | " \n", 2407 | " \n", 2408 | "
ColumnIDTypeRawLengthFormattedLengthNFLNFD
0sepal_length1double81200
1sepal_width2double81200
2petal_length3double81200
3petal_width4double81200
4species5varchar101000
\n", 2409 | "
\n", 2410 | "
\n", 2411 | "
\n", 2412 | "

elapsed 0.000687s · user 0.001s · mem 0.169MB

" 2413 | ], 2414 | "text/plain": [ 2415 | "[ColumnInfo]\n", 2416 | "\n", 2417 | " Column ID Type RawLength FormattedLength NFL NFD\n", 2418 | " 0 sepal_length 1 double 8 12 0 0\n", 2419 | " 1 sepal_width 2 double 8 12 0 0\n", 2420 | " 2 petal_length 3 double 8 12 0 0\n", 2421 | " 3 petal_width 4 double 8 12 0 0\n", 2422 | " 4 species 5 varchar 10 10 0 0\n", 2423 | "\n", 2424 | "+ Elapsed: 0.000687s, user: 0.001s, mem: 0.169mb" 2425 | ] 2426 | }, 2427 | "execution_count": 69, 2428 | "metadata": {}, 2429 | "output_type": "execute_result" 2430 | } 2431 | ], 2432 | "source": [ 2433 | "newtbl.columninfo()" 2434 | ] 2435 | }, 2436 | { 2437 | "cell_type": "markdown", 2438 | "metadata": {}, 2439 | "source": [ 2440 | "### The CASTable Action Interface" 2441 | ] 2442 | }, 2443 | { 2444 | "cell_type": "code", 2445 | "execution_count": 70, 2446 | "metadata": { 2447 | "collapsed": false 2448 | }, 2449 | "outputs": [ 2450 | { 2451 | "name": "stderr", 2452 | "output_type": "stream", 2453 | "text": [ 2454 | "ERROR: The table DATA.IRIS already exists in caslib CASUSER(username).\n", 2455 | "ERROR: The action stopped due to errors.\n" 2456 | ] 2457 | }, 2458 | { 2459 | "data": { 2460 | "text/html": [ 2461 | "
§ caslib
\n", 2462 | "
\n", 2463 | "
CASUSER(username)
\n", 2464 | "
\n", 2465 | "

§ tableName
\n", 2466 | "
\n", 2467 | "
DATA.IRIS
\n", 2468 | "
\n", 2469 | "

§ casTable
\n", 2470 | "
\n", 2471 | "
CASTable('DATA.IRIS', caslib='CASUSER(username)')
\n", 2472 | "
\n", 2473 | "
\n", 2474 | "

elapsed 0.000518s · mem 0.123MB

" 2475 | ], 2476 | "text/plain": [ 2477 | "[caslib]\n", 2478 | "\n", 2479 | " 'CASUSER(username)'\n", 2480 | "\n", 2481 | "[tableName]\n", 2482 | "\n", 2483 | " 'DATA.IRIS'\n", 2484 | "\n", 2485 | "[casTable]\n", 2486 | "\n", 2487 | " CASTable('DATA.IRIS', caslib='CASUSER(username)')\n", 2488 | "\n", 2489 | "+ Elapsed: 0.000518s, mem: 0.123mb" 2490 | ] 2491 | }, 2492 | "execution_count": 70, 2493 | "metadata": {}, 2494 | "output_type": "execute_result" 2495 | } 2496 | ], 2497 | "source": [ 2498 | "out = conn.loadtable('data/iris.csv', caslib='casuser')\n", 2499 | "out" 2500 | ] 2501 | }, 2502 | { 2503 | "cell_type": "code", 2504 | "execution_count": 71, 2505 | "metadata": { 2506 | "collapsed": true 2507 | }, 2508 | "outputs": [], 2509 | "source": [ 2510 | "iris = out.casTable" 2511 | ] 2512 | }, 2513 | { 2514 | "cell_type": "code", 2515 | "execution_count": 74, 2516 | "metadata": { 2517 | "collapsed": false 2518 | }, 2519 | "outputs": [ 2520 | { 2521 | "data": { 2522 | "text/plain": [ 2523 | "?.simple.Summary(__table__=CASTable('DATA.IRIS', caslib='CASUSER(username)'))" 2524 | ] 2525 | }, 2526 | "execution_count": 74, 2527 | "metadata": {}, 2528 | "output_type": "execute_result" 2529 | } 2530 | ], 2531 | "source": [ 2532 | "summ = iris.Summary()\n", 2533 | "summ" 2534 | ] 2535 | }, 2536 | { 2537 | "cell_type": "code", 2538 | "execution_count": 75, 2539 | "metadata": { 2540 | "collapsed": false 2541 | }, 2542 | "outputs": [ 2543 | { 2544 | "data": { 2545 | "text/html": [ 2546 | "
§ Summary
\n", 2547 | "
\n", 2548 | "
\n", 2549 | "\n", 2550 | " \n", 2551 | " \n", 2552 | " \n", 2553 | " \n", 2554 | " \n", 2555 | " \n", 2556 | " \n", 2557 | " \n", 2558 | " \n", 2559 | " \n", 2560 | " \n", 2561 | " \n", 2562 | " \n", 2563 | " \n", 2564 | " \n", 2565 | " \n", 2566 | " \n", 2567 | " \n", 2568 | " \n", 2569 | " \n", 2570 | " \n", 2571 | " \n", 2572 | " \n", 2573 | " \n", 2574 | " \n", 2575 | " \n", 2576 | " \n", 2577 | " \n", 2578 | " \n", 2579 | " \n", 2580 | " \n", 2581 | " \n", 2582 | " \n", 2583 | " \n", 2584 | " \n", 2585 | " \n", 2586 | " \n", 2587 | " \n", 2588 | " \n", 2589 | " \n", 2590 | " \n", 2591 | " \n", 2592 | " \n", 2593 | " \n", 2594 | " \n", 2595 | " \n", 2596 | " \n", 2597 | " \n", 2598 | " \n", 2599 | " \n", 2600 | " \n", 2601 | " \n", 2602 | " \n", 2603 | " \n", 2604 | " \n", 2605 | " \n", 2606 | " \n", 2607 | " \n", 2608 | " \n", 2609 | " \n", 2610 | " \n", 2611 | " \n", 2612 | " \n", 2613 | " \n", 2614 | " \n", 2615 | " \n", 2616 | " \n", 2617 | " \n", 2618 | " \n", 2619 | " \n", 2620 | " \n", 2621 | " \n", 2622 | " \n", 2623 | " \n", 2624 | " \n", 2625 | " \n", 2626 | " \n", 2627 | " \n", 2628 | " \n", 2629 | " \n", 2630 | " \n", 2631 | " \n", 2632 | " \n", 2633 | " \n", 2634 | " \n", 2635 | " \n", 2636 | " \n", 2637 | " \n", 2638 | " \n", 2639 | " \n", 2640 | " \n", 2641 | " \n", 2642 | " \n", 2643 | " \n", 2644 | "
Descriptive Statistics for DATA.IRIS
ColumnMinMaxNNMissMeanSumStdStdErrVarUSSCSSCVTValueProbT
0sepal_length4.37.9150.00.05.843333876.50.8280660.0676110.6856945223.85102.16833314.17112686.4253753.331256e-129
1sepal_width2.04.4150.00.03.054000458.10.4335940.0354030.1880041427.0528.01260014.19758786.2642974.374977e-129
2petal_length1.06.9150.00.03.758667563.81.7644200.1440643.1131792583.00463.86373346.94272126.0901981.994305e-57
3petal_width0.12.5150.00.01.198667179.80.7631610.0623120.582414302.3086.77973363.66747019.2365883.209704e-42
\n", 2645 | "
\n", 2646 | "
\n", 2647 | "
\n", 2648 | "

elapsed 0.00621s · user 0.004s · sys 0.005s · mem 1.73MB

" 2649 | ], 2650 | "text/plain": [ 2651 | "[Summary]\n", 2652 | "\n", 2653 | " Descriptive Statistics for DATA.IRIS\n", 2654 | " \n", 2655 | " Column Min Max N NMiss Mean Sum Std StdErr \\\n", 2656 | " 0 sepal_length 4.3 7.9 150.0 0.0 5.843333 876.5 0.828066 0.067611 \n", 2657 | " 1 sepal_width 2.0 4.4 150.0 0.0 3.054000 458.1 0.433594 0.035403 \n", 2658 | " 2 petal_length 1.0 6.9 150.0 0.0 3.758667 563.8 1.764420 0.144064 \n", 2659 | " 3 petal_width 0.1 2.5 150.0 0.0 1.198667 179.8 0.763161 0.062312 \n", 2660 | " \n", 2661 | " Var USS CSS CV TValue ProbT \n", 2662 | " 0 0.685694 5223.85 102.168333 14.171126 86.425375 3.331256e-129 \n", 2663 | " 1 0.188004 1427.05 28.012600 14.197587 86.264297 4.374977e-129 \n", 2664 | " 2 3.113179 2583.00 463.863733 46.942721 26.090198 1.994305e-57 \n", 2665 | " 3 0.582414 302.30 86.779733 63.667470 19.236588 3.209704e-42 \n", 2666 | "\n", 2667 | "+ Elapsed: 0.00621s, user: 0.004s, sys: 0.005s, mem: 1.73mb" 2668 | ] 2669 | }, 2670 | "execution_count": 75, 2671 | "metadata": {}, 2672 | "output_type": "execute_result" 2673 | } 2674 | ], 2675 | "source": [ 2676 | "summ()" 2677 | ] 2678 | }, 2679 | { 2680 | "cell_type": "markdown", 2681 | "metadata": {}, 2682 | "source": [ 2683 | "### Setting CASTable Parameters" 2684 | ] 2685 | }, 2686 | { 2687 | "cell_type": "code", 2688 | "execution_count": 76, 2689 | "metadata": { 2690 | "collapsed": true 2691 | }, 2692 | "outputs": [], 2693 | "source": [ 2694 | "iris?" 2695 | ] 2696 | }, 2697 | { 2698 | "cell_type": "code", 2699 | "execution_count": 77, 2700 | "metadata": { 2701 | "collapsed": false 2702 | }, 2703 | "outputs": [ 2704 | { 2705 | "data": { 2706 | "text/plain": [ 2707 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor =\\n sepal_length * petal_length;', where='sepal_length > 6.8 and \\n species = \"virginica\"')" 2708 | ] 2709 | }, 2710 | "execution_count": 77, 2711 | "metadata": {}, 2712 | "output_type": "execute_result" 2713 | } 2714 | ], 2715 | "source": [ 2716 | "iris = conn.CASTable('data.iris', caslib='casuser', \n", 2717 | " where='''sepal_length > 6.8 and \n", 2718 | " species = \"virginica\"''',\n", 2719 | " computedvars=['length_factor'],\n", 2720 | " computedvarsprogram='''length_factor =\n", 2721 | " sepal_length * petal_length;''')\n", 2722 | "iris" 2723 | ] 2724 | }, 2725 | { 2726 | "cell_type": "code", 2727 | "execution_count": 78, 2728 | "metadata": { 2729 | "collapsed": false, 2730 | "scrolled": true 2731 | }, 2732 | "outputs": [ 2733 | { 2734 | "data": { 2735 | "text/html": [ 2736 | "
§ Fetch
\n", 2737 | "
\n", 2738 | "
\n", 2739 | "\n", 2740 | " \n", 2741 | " \n", 2742 | " \n", 2743 | " \n", 2744 | " \n", 2745 | " \n", 2746 | " \n", 2747 | " \n", 2748 | " \n", 2749 | " \n", 2750 | " \n", 2751 | " \n", 2752 | " \n", 2753 | " \n", 2754 | " \n", 2755 | " \n", 2756 | " \n", 2757 | " \n", 2758 | " \n", 2759 | " \n", 2760 | " \n", 2761 | " \n", 2762 | " \n", 2763 | " \n", 2764 | " \n", 2765 | " \n", 2766 | " \n", 2767 | " \n", 2768 | " \n", 2769 | " \n", 2770 | " \n", 2771 | " \n", 2772 | " \n", 2773 | " \n", 2774 | " \n", 2775 | " \n", 2776 | " \n", 2777 | " \n", 2778 | " \n", 2779 | " \n", 2780 | " \n", 2781 | " \n", 2782 | " \n", 2783 | " \n", 2784 | " \n", 2785 | " \n", 2786 | " \n", 2787 | " \n", 2788 | " \n", 2789 | " \n", 2790 | " \n", 2791 | " \n", 2792 | " \n", 2793 | " \n", 2794 | " \n", 2795 | " \n", 2796 | " \n", 2797 | " \n", 2798 | " \n", 2799 | " \n", 2800 | " \n", 2801 | " \n", 2802 | " \n", 2803 | " \n", 2804 | " \n", 2805 | " \n", 2806 | " \n", 2807 | " \n", 2808 | " \n", 2809 | " \n", 2810 | " \n", 2811 | " \n", 2812 | " \n", 2813 | " \n", 2814 | " \n", 2815 | " \n", 2816 | " \n", 2817 | " \n", 2818 | " \n", 2819 | " \n", 2820 | " \n", 2821 | " \n", 2822 | " \n", 2823 | " \n", 2824 | " \n", 2825 | " \n", 2826 | " \n", 2827 | " \n", 2828 | " \n", 2829 | " \n", 2830 | " \n", 2831 | " \n", 2832 | " \n", 2833 | " \n", 2834 | " \n", 2835 | " \n", 2836 | " \n", 2837 | " \n", 2838 | " \n", 2839 | " \n", 2840 | "
Selected Rows from Table DATA.IRIS
sepal_lengthpetal_lengthlength_factor
06.95.437.26
16.95.135.19
27.15.941.89
37.66.650.16
47.36.345.99
57.26.143.92
67.76.751.59
77.76.953.13
86.95.739.33
97.76.751.59
107.26.043.20
117.25.841.76
127.46.145.14
137.96.450.56
147.76.146.97
\n", 2841 | "
\n", 2842 | "
\n", 2843 | "
\n", 2844 | "

elapsed 0.0135s · user 0.013s · sys 0.003s · mem 2.54MB

" 2845 | ], 2846 | "text/plain": [ 2847 | "[Fetch]\n", 2848 | "\n", 2849 | " Selected Rows from Table DATA.IRIS\n", 2850 | " \n", 2851 | " sepal_length petal_length length_factor\n", 2852 | " 0 6.9 5.4 37.26\n", 2853 | " 1 6.9 5.1 35.19\n", 2854 | " 2 7.1 5.9 41.89\n", 2855 | " 3 7.6 6.6 50.16\n", 2856 | " 4 7.3 6.3 45.99\n", 2857 | " 5 7.2 6.1 43.92\n", 2858 | " 6 7.7 6.7 51.59\n", 2859 | " 7 7.7 6.9 53.13\n", 2860 | " 8 6.9 5.7 39.33\n", 2861 | " 9 7.7 6.7 51.59\n", 2862 | " 10 7.2 6.0 43.20\n", 2863 | " 11 7.2 5.8 41.76\n", 2864 | " 12 7.4 6.1 45.14\n", 2865 | " 13 7.9 6.4 50.56\n", 2866 | " 14 7.7 6.1 46.97\n", 2867 | "\n", 2868 | "+ Elapsed: 0.0135s, user: 0.013s, sys: 0.003s, mem: 2.54mb" 2869 | ] 2870 | }, 2871 | "execution_count": 78, 2872 | "metadata": {}, 2873 | "output_type": "execute_result" 2874 | } 2875 | ], 2876 | "source": [ 2877 | "iris.fetch(fetchvars=['sepal_length', 'petal_length', 'length_factor'])" 2878 | ] 2879 | }, 2880 | { 2881 | "cell_type": "markdown", 2882 | "metadata": {}, 2883 | "source": [ 2884 | "Using a **CASTable** object as a **casout=** parameter value." 2885 | ] 2886 | }, 2887 | { 2888 | "cell_type": "raw", 2889 | "metadata": {}, 2890 | "source": [ 2891 | "outtbl = conn.CASTable('summout', caslib='casuser', promote=True)\n", 2892 | "outtbl" 2893 | ] 2894 | }, 2895 | { 2896 | "cell_type": "code", 2897 | "execution_count": 84, 2898 | "metadata": { 2899 | "collapsed": false 2900 | }, 2901 | "outputs": [ 2902 | { 2903 | "data": { 2904 | "text/html": [ 2905 | "
§ OutputCasTables
\n", 2906 | "
\n", 2907 | "
\n", 2908 | "\n", 2909 | " \n", 2910 | " \n", 2911 | " \n", 2912 | " \n", 2913 | " \n", 2914 | " \n", 2915 | " \n", 2916 | " \n", 2917 | " \n", 2918 | " \n", 2919 | " \n", 2920 | " \n", 2921 | " \n", 2922 | " \n", 2923 | " \n", 2924 | " \n", 2925 | " \n", 2926 | " \n", 2927 | " \n", 2928 | " \n", 2929 | "
casLibNameRowsColumnscasTable
0CASUSER(username)summout515CASTable('summout', caslib='CASUSER(username)')
\n", 2930 | "
\n", 2931 | "
\n", 2932 | "
\n", 2933 | "

elapsed 0.0177s · user 0.016s · sys 0.006s · mem 2.62MB

" 2934 | ], 2935 | "text/plain": [ 2936 | "[OutputCasTables]\n", 2937 | "\n", 2938 | " casLib Name Rows Columns \\\n", 2939 | " 0 CASUSER(username) summout 5 15 \n", 2940 | " \n", 2941 | " casTable \n", 2942 | " 0 CASTable('summout', caslib='CASUSER(username)') \n", 2943 | "\n", 2944 | "+ Elapsed: 0.0177s, user: 0.016s, sys: 0.006s, mem: 2.62mb" 2945 | ] 2946 | }, 2947 | "execution_count": 84, 2948 | "metadata": {}, 2949 | "output_type": "execute_result" 2950 | } 2951 | ], 2952 | "source": [ 2953 | "iris.summary(casout=outtbl)" 2954 | ] 2955 | }, 2956 | { 2957 | "cell_type": "code", 2958 | "execution_count": 85, 2959 | "metadata": { 2960 | "collapsed": false 2961 | }, 2962 | "outputs": [ 2963 | { 2964 | "data": { 2965 | "text/html": [ 2966 | "
§ Fetch
\n", 2967 | "
\n", 2968 | "
\n", 2969 | "\n", 2970 | " \n", 2971 | " \n", 2972 | " \n", 2973 | " \n", 2974 | " \n", 2975 | " \n", 2976 | " \n", 2977 | " \n", 2978 | " \n", 2979 | " \n", 2980 | " \n", 2981 | " \n", 2982 | " \n", 2983 | " \n", 2984 | " \n", 2985 | " \n", 2986 | " \n", 2987 | " \n", 2988 | " \n", 2989 | " \n", 2990 | " \n", 2991 | " \n", 2992 | " \n", 2993 | " \n", 2994 | " \n", 2995 | " \n", 2996 | " \n", 2997 | " \n", 2998 | " \n", 2999 | " \n", 3000 | " \n", 3001 | " \n", 3002 | " \n", 3003 | " \n", 3004 | " \n", 3005 | " \n", 3006 | " \n", 3007 | " \n", 3008 | " \n", 3009 | " \n", 3010 | " \n", 3011 | " \n", 3012 | " \n", 3013 | " \n", 3014 | " \n", 3015 | " \n", 3016 | " \n", 3017 | " \n", 3018 | " \n", 3019 | " \n", 3020 | " \n", 3021 | " \n", 3022 | " \n", 3023 | " \n", 3024 | " \n", 3025 | " \n", 3026 | " \n", 3027 | " \n", 3028 | " \n", 3029 | " \n", 3030 | " \n", 3031 | " \n", 3032 | " \n", 3033 | " \n", 3034 | " \n", 3035 | " \n", 3036 | " \n", 3037 | " \n", 3038 | " \n", 3039 | " \n", 3040 | " \n", 3041 | " \n", 3042 | " \n", 3043 | " \n", 3044 | " \n", 3045 | " \n", 3046 | " \n", 3047 | " \n", 3048 | " \n", 3049 | " \n", 3050 | " \n", 3051 | " \n", 3052 | " \n", 3053 | " \n", 3054 | " \n", 3055 | " \n", 3056 | " \n", 3057 | " \n", 3058 | " \n", 3059 | " \n", 3060 | " \n", 3061 | " \n", 3062 | " \n", 3063 | " \n", 3064 | " \n", 3065 | " \n", 3066 | " \n", 3067 | " \n", 3068 | " \n", 3069 | " \n", 3070 | " \n", 3071 | " \n", 3072 | " \n", 3073 | " \n", 3074 | " \n", 3075 | " \n", 3076 | " \n", 3077 | " \n", 3078 | " \n", 3079 | " \n", 3080 | " \n", 3081 | " \n", 3082 | "
Selected Rows from Table SUMMOUT
_Column__Min__Max__NObs__NMiss__Mean__Sum__Std__StdErr__Var__USS__CSS__CV__T__PRT_
0sepal_length6.907.9015.00.07.360000110.400.3376390.0871780.114000814.14001.5960004.58748584.4249902.332581e-20
1sepal_width2.603.8015.00.03.12666746.900.3534860.0912700.124952148.39001.74933311.30552434.2574436.662768e-15
2petal_length5.106.9015.00.06.12000091.800.5017110.1295410.251714565.34003.5240008.19789847.2436157.680656e-17
3petal_width1.602.5015.00.02.08666731.300.2416220.0623860.05838166.13000.81733311.57930533.4474589.278838e-15
4length_factor35.1953.1315.00.045.178667677.685.5276111.42722330.55448431044.4416427.76277312.23500331.6549451.987447e-14
\n", 3083 | "
\n", 3084 | "
\n", 3085 | "
\n", 3086 | "

elapsed 0.00372s · user 0.003s · sys 0.001s · mem 1.6MB

" 3087 | ], 3088 | "text/plain": [ 3089 | "[Fetch]\n", 3090 | "\n", 3091 | " Selected Rows from Table SUMMOUT\n", 3092 | " \n", 3093 | " _Column_ _Min_ _Max_ _NObs_ _NMiss_ _Mean_ _Sum_ _Std_ \\\n", 3094 | " 0 sepal_length 6.90 7.90 15.0 0.0 7.360000 110.40 0.337639 \n", 3095 | " 1 sepal_width 2.60 3.80 15.0 0.0 3.126667 46.90 0.353486 \n", 3096 | " 2 petal_length 5.10 6.90 15.0 0.0 6.120000 91.80 0.501711 \n", 3097 | " 3 petal_width 1.60 2.50 15.0 0.0 2.086667 31.30 0.241622 \n", 3098 | " 4 length_factor 35.19 53.13 15.0 0.0 45.178667 677.68 5.527611 \n", 3099 | " \n", 3100 | " _StdErr_ _Var_ _USS_ _CSS_ _CV_ _T_ \\\n", 3101 | " 0 0.087178 0.114000 814.1400 1.596000 4.587485 84.424990 \n", 3102 | " 1 0.091270 0.124952 148.3900 1.749333 11.305524 34.257443 \n", 3103 | " 2 0.129541 0.251714 565.3400 3.524000 8.197898 47.243615 \n", 3104 | " 3 0.062386 0.058381 66.1300 0.817333 11.579305 33.447458 \n", 3105 | " 4 1.427223 30.554484 31044.4416 427.762773 12.235003 31.654945 \n", 3106 | " \n", 3107 | " _PRT_ \n", 3108 | " 0 2.332581e-20 \n", 3109 | " 1 6.662768e-15 \n", 3110 | " 2 7.680656e-17 \n", 3111 | " 3 9.278838e-15 \n", 3112 | " 4 1.987447e-14 \n", 3113 | "\n", 3114 | "+ Elapsed: 0.00372s, user: 0.003s, sys: 0.001s, mem: 1.6mb" 3115 | ] 3116 | }, 3117 | "execution_count": 85, 3118 | "metadata": {}, 3119 | "output_type": "execute_result" 3120 | } 3121 | ], 3122 | "source": [ 3123 | "outtbl.fetch()" 3124 | ] 3125 | }, 3126 | { 3127 | "cell_type": "markdown", 3128 | "metadata": {}, 3129 | "source": [ 3130 | "### Managing Parameters using the Method Interface" 3131 | ] 3132 | }, 3133 | { 3134 | "cell_type": "code", 3135 | "execution_count": 89, 3136 | "metadata": { 3137 | "collapsed": false 3138 | }, 3139 | "outputs": [ 3140 | { 3141 | "data": { 3142 | "text/plain": [ 3143 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3144 | ] 3145 | }, 3146 | "execution_count": 89, 3147 | "metadata": {}, 3148 | "output_type": "execute_result" 3149 | } 3150 | ], 3151 | "source": [ 3152 | "iris = conn.CASTable('data.iris', caslib='casuser')\n", 3153 | "iris.set_param('where', 'sepal_length > 6.8 and species = \"virginica\"')\n", 3154 | "iris.set_param('computedvars', ['length_factor'])\n", 3155 | "iris.set_param('computedvarsprogram', 'length_factor = sepal_length * petal_length;')\n", 3156 | "iris" 3157 | ] 3158 | }, 3159 | { 3160 | "cell_type": "code", 3161 | "execution_count": 90, 3162 | "metadata": { 3163 | "collapsed": false 3164 | }, 3165 | "outputs": [ 3166 | { 3167 | "data": { 3168 | "text/html": [ 3169 | "
§ Fetch
\n", 3170 | "
\n", 3171 | "
\n", 3172 | "\n", 3173 | " \n", 3174 | " \n", 3175 | " \n", 3176 | " \n", 3177 | " \n", 3178 | " \n", 3179 | " \n", 3180 | " \n", 3181 | " \n", 3182 | " \n", 3183 | " \n", 3184 | " \n", 3185 | " \n", 3186 | " \n", 3187 | " \n", 3188 | " \n", 3189 | " \n", 3190 | " \n", 3191 | " \n", 3192 | " \n", 3193 | " \n", 3194 | " \n", 3195 | " \n", 3196 | " \n", 3197 | " \n", 3198 | " \n", 3199 | " \n", 3200 | " \n", 3201 | " \n", 3202 | " \n", 3203 | " \n", 3204 | " \n", 3205 | " \n", 3206 | " \n", 3207 | " \n", 3208 | " \n", 3209 | " \n", 3210 | " \n", 3211 | " \n", 3212 | " \n", 3213 | "
Selected Rows from Table DATA.IRIS
sepal_lengthpetal_lengthlength_factor
06.95.437.26
16.95.135.19
27.15.941.89
37.66.650.16
47.36.345.99
\n", 3214 | "
\n", 3215 | "
\n", 3216 | "
\n", 3217 | "

elapsed 0.0137s · user 0.011s · sys 0.005s · mem 2.47MB

" 3218 | ], 3219 | "text/plain": [ 3220 | "[Fetch]\n", 3221 | "\n", 3222 | " Selected Rows from Table DATA.IRIS\n", 3223 | " \n", 3224 | " sepal_length petal_length length_factor\n", 3225 | " 0 6.9 5.4 37.26\n", 3226 | " 1 6.9 5.1 35.19\n", 3227 | " 2 7.1 5.9 41.89\n", 3228 | " 3 7.6 6.6 50.16\n", 3229 | " 4 7.3 6.3 45.99\n", 3230 | "\n", 3231 | "+ Elapsed: 0.0137s, user: 0.011s, sys: 0.005s, mem: 2.47mb" 3232 | ] 3233 | }, 3234 | "execution_count": 90, 3235 | "metadata": {}, 3236 | "output_type": "execute_result" 3237 | } 3238 | ], 3239 | "source": [ 3240 | "iris.fetch(to=5, fetchvars=['sepal_length', 'petal_length', 'length_factor'])" 3241 | ] 3242 | }, 3243 | { 3244 | "cell_type": "markdown", 3245 | "metadata": {}, 3246 | "source": [ 3247 | "All of the following are equivalent ways of setting parameters." 3248 | ] 3249 | }, 3250 | { 3251 | "cell_type": "code", 3252 | "execution_count": 91, 3253 | "metadata": { 3254 | "collapsed": false 3255 | }, 3256 | "outputs": [ 3257 | { 3258 | "data": { 3259 | "text/plain": [ 3260 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3261 | ] 3262 | }, 3263 | "execution_count": 91, 3264 | "metadata": {}, 3265 | "output_type": "execute_result" 3266 | } 3267 | ], 3268 | "source": [ 3269 | "iris.set_params('where', 'sepal_length > 6.8 and species = \"virginica\"',\n", 3270 | " 'computedvars', ['length_factor'],\n", 3271 | " 'computedvarsprogram', 'length_factor = sepal_length * petal_length;')\n", 3272 | "iris" 3273 | ] 3274 | }, 3275 | { 3276 | "cell_type": "code", 3277 | "execution_count": 92, 3278 | "metadata": { 3279 | "collapsed": false 3280 | }, 3281 | "outputs": [ 3282 | { 3283 | "data": { 3284 | "text/plain": [ 3285 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3286 | ] 3287 | }, 3288 | "execution_count": 92, 3289 | "metadata": {}, 3290 | "output_type": "execute_result" 3291 | } 3292 | ], 3293 | "source": [ 3294 | "iris.set_params(('where', 'sepal_length > 6.8 and species = \"virginica\"'),\n", 3295 | " ('computedvars', ['length_factor']),\n", 3296 | " ('computedvarsprogram', 'length_factor = sepal_length * petal_length;'))\n", 3297 | "iris" 3298 | ] 3299 | }, 3300 | { 3301 | "cell_type": "code", 3302 | "execution_count": 93, 3303 | "metadata": { 3304 | "collapsed": false 3305 | }, 3306 | "outputs": [ 3307 | { 3308 | "data": { 3309 | "text/plain": [ 3310 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3311 | ] 3312 | }, 3313 | "execution_count": 93, 3314 | "metadata": {}, 3315 | "output_type": "execute_result" 3316 | } 3317 | ], 3318 | "source": [ 3319 | "iris.set_params(where='sepal_length > 6.8 and species = \"virginica\"',\n", 3320 | " computedvars=['length_factor'],\n", 3321 | " computedvarsprogram='length_factor = sepal_length * petal_length;')\n", 3322 | "iris" 3323 | ] 3324 | }, 3325 | { 3326 | "cell_type": "code", 3327 | "execution_count": 94, 3328 | "metadata": { 3329 | "collapsed": false 3330 | }, 3331 | "outputs": [ 3332 | { 3333 | "data": { 3334 | "text/plain": [ 3335 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3336 | ] 3337 | }, 3338 | "execution_count": 94, 3339 | "metadata": {}, 3340 | "output_type": "execute_result" 3341 | } 3342 | ], 3343 | "source": [ 3344 | "iris.set_params({'where': 'sepal_length > 6.8 and species = \"virginica\"',\n", 3345 | " 'computedvars': ['length_factor'],\n", 3346 | " 'computedvarsprogram': 'length_factor = sepal_length * petal_length;'})\n", 3347 | "iris" 3348 | ] 3349 | }, 3350 | { 3351 | "cell_type": "markdown", 3352 | "metadata": {}, 3353 | "source": [ 3354 | "Checking and retrieving parameters." 3355 | ] 3356 | }, 3357 | { 3358 | "cell_type": "code", 3359 | "execution_count": 95, 3360 | "metadata": { 3361 | "collapsed": false 3362 | }, 3363 | "outputs": [ 3364 | { 3365 | "data": { 3366 | "text/plain": [ 3367 | "True" 3368 | ] 3369 | }, 3370 | "execution_count": 95, 3371 | "metadata": {}, 3372 | "output_type": "execute_result" 3373 | } 3374 | ], 3375 | "source": [ 3376 | "iris.has_param('where')" 3377 | ] 3378 | }, 3379 | { 3380 | "cell_type": "code", 3381 | "execution_count": 96, 3382 | "metadata": { 3383 | "collapsed": false 3384 | }, 3385 | "outputs": [ 3386 | { 3387 | "data": { 3388 | "text/plain": [ 3389 | "False" 3390 | ] 3391 | }, 3392 | "execution_count": 96, 3393 | "metadata": {}, 3394 | "output_type": "execute_result" 3395 | } 3396 | ], 3397 | "source": [ 3398 | "iris.has_param('groupby')" 3399 | ] 3400 | }, 3401 | { 3402 | "cell_type": "code", 3403 | "execution_count": 97, 3404 | "metadata": { 3405 | "collapsed": false 3406 | }, 3407 | "outputs": [ 3408 | { 3409 | "data": { 3410 | "text/plain": [ 3411 | "'sepal_length > 6.8 and species = \"virginica\"'" 3412 | ] 3413 | }, 3414 | "execution_count": 97, 3415 | "metadata": {}, 3416 | "output_type": "execute_result" 3417 | } 3418 | ], 3419 | "source": [ 3420 | "iris.get_param('where')" 3421 | ] 3422 | }, 3423 | { 3424 | "cell_type": "code", 3425 | "execution_count": 98, 3426 | "metadata": { 3427 | "collapsed": false 3428 | }, 3429 | "outputs": [ 3430 | { 3431 | "data": { 3432 | "text/plain": [ 3433 | "{'computedvars': ['length_factor'],\n", 3434 | " 'where': 'sepal_length > 6.8 and species = \"virginica\"'}" 3435 | ] 3436 | }, 3437 | "execution_count": 98, 3438 | "metadata": {}, 3439 | "output_type": "execute_result" 3440 | } 3441 | ], 3442 | "source": [ 3443 | "iris.get_params('where', 'computedvars')" 3444 | ] 3445 | }, 3446 | { 3447 | "cell_type": "markdown", 3448 | "metadata": {}, 3449 | "source": [ 3450 | "Deleting parameters." 3451 | ] 3452 | }, 3453 | { 3454 | "cell_type": "code", 3455 | "execution_count": 99, 3456 | "metadata": { 3457 | "collapsed": false 3458 | }, 3459 | "outputs": [ 3460 | { 3461 | "data": { 3462 | "text/plain": [ 3463 | "CASTable('data.iris', caslib='casuser', computedvars=['length_factor'], computedvarsprogram='length_factor = sepal_length * petal_length;', where='sepal_length > 6.8 and species = \"virginica\"')" 3464 | ] 3465 | }, 3466 | "execution_count": 99, 3467 | "metadata": {}, 3468 | "output_type": "execute_result" 3469 | } 3470 | ], 3471 | "source": [ 3472 | "iris" 3473 | ] 3474 | }, 3475 | { 3476 | "cell_type": "code", 3477 | "execution_count": 100, 3478 | "metadata": { 3479 | "collapsed": false 3480 | }, 3481 | "outputs": [ 3482 | { 3483 | "data": { 3484 | "text/plain": [ 3485 | "CASTable('data.iris', caslib='casuser', where='sepal_length > 6.8 and species = \"virginica\"')" 3486 | ] 3487 | }, 3488 | "execution_count": 100, 3489 | "metadata": {}, 3490 | "output_type": "execute_result" 3491 | } 3492 | ], 3493 | "source": [ 3494 | "iris.del_params('computedvars', 'computedvarsprogram')\n", 3495 | "iris" 3496 | ] 3497 | }, 3498 | { 3499 | "cell_type": "markdown", 3500 | "metadata": {}, 3501 | "source": [ 3502 | "### Managing Parameters using the Attribute Interface" 3503 | ] 3504 | }, 3505 | { 3506 | "cell_type": "code", 3507 | "execution_count": 101, 3508 | "metadata": { 3509 | "collapsed": false 3510 | }, 3511 | "outputs": [ 3512 | { 3513 | "data": { 3514 | "text/plain": [ 3515 | "CASTable('data.iris', caslib='casuser')" 3516 | ] 3517 | }, 3518 | "execution_count": 101, 3519 | "metadata": {}, 3520 | "output_type": "execute_result" 3521 | } 3522 | ], 3523 | "source": [ 3524 | "iris = conn.CASTable('data.iris', caslib='casuser')\n", 3525 | "iris" 3526 | ] 3527 | }, 3528 | { 3529 | "cell_type": "code", 3530 | "execution_count": 102, 3531 | "metadata": { 3532 | "collapsed": false 3533 | }, 3534 | "outputs": [ 3535 | { 3536 | "data": { 3537 | "text/plain": [ 3538 | "CASTable('data.iris', caslib='casuser', where='sepal_length > 6.8 and species = \"virginica\"')" 3539 | ] 3540 | }, 3541 | "execution_count": 102, 3542 | "metadata": {}, 3543 | "output_type": "execute_result" 3544 | } 3545 | ], 3546 | "source": [ 3547 | "iris.params.where = 'sepal_length > 6.8 and species = \"virginica\"'\n", 3548 | "iris" 3549 | ] 3550 | }, 3551 | { 3552 | "cell_type": "code", 3553 | "execution_count": 103, 3554 | "metadata": { 3555 | "collapsed": false 3556 | }, 3557 | "outputs": [ 3558 | { 3559 | "data": { 3560 | "text/plain": [ 3561 | "CASTable('data.iris', caslib='casuser', groupby=['species', 'sepal_length'], where='sepal_length > 6.8 and species = \"virginica\"')" 3562 | ] 3563 | }, 3564 | "execution_count": 103, 3565 | "metadata": {}, 3566 | "output_type": "execute_result" 3567 | } 3568 | ], 3569 | "source": [ 3570 | "iris.params.groupby[0] = 'species'\n", 3571 | "iris.params.groupby[1] = 'sepal_length'\n", 3572 | "iris" 3573 | ] 3574 | }, 3575 | { 3576 | "cell_type": "code", 3577 | "execution_count": 104, 3578 | "metadata": { 3579 | "collapsed": false 3580 | }, 3581 | "outputs": [ 3582 | { 3583 | "data": { 3584 | "text/plain": [ 3585 | "CASTable('data.iris', caslib='casuser')" 3586 | ] 3587 | }, 3588 | "execution_count": 104, 3589 | "metadata": {}, 3590 | "output_type": "execute_result" 3591 | } 3592 | ], 3593 | "source": [ 3594 | "del iris.params.groupby\n", 3595 | "del iris.params.where\n", 3596 | "iris" 3597 | ] 3598 | }, 3599 | { 3600 | "cell_type": "markdown", 3601 | "metadata": {}, 3602 | "source": [ 3603 | "Parameters can be set directly on the **CASTable** object as well." 3604 | ] 3605 | }, 3606 | { 3607 | "cell_type": "code", 3608 | "execution_count": 105, 3609 | "metadata": { 3610 | "collapsed": false 3611 | }, 3612 | "outputs": [ 3613 | { 3614 | "data": { 3615 | "text/plain": [ 3616 | "CASTable('data.iris', caslib='casuser', groupby=['species'], where='sepal_length > 6.8 and species = \"virginica\"')" 3617 | ] 3618 | }, 3619 | "execution_count": 105, 3620 | "metadata": {}, 3621 | "output_type": "execute_result" 3622 | } 3623 | ], 3624 | "source": [ 3625 | "iris.groupby = ['species']\n", 3626 | "iris.where = 'sepal_length > 6.8 and species = \"virginica\"'\n", 3627 | "iris" 3628 | ] 3629 | }, 3630 | { 3631 | "cell_type": "markdown", 3632 | "metadata": {}, 3633 | "source": [ 3634 | "### Persisting **CASTable** Parameters" 3635 | ] 3636 | }, 3637 | { 3638 | "cell_type": "code", 3639 | "execution_count": 107, 3640 | "metadata": { 3641 | "collapsed": false 3642 | }, 3643 | "outputs": [ 3644 | { 3645 | "data": { 3646 | "text/plain": [ 3647 | "CASTable('data.iris', caslib='casuser', groupby=['species'], where='sepal_length > 6.8 and species = \"virginica\"')" 3648 | ] 3649 | }, 3650 | "execution_count": 107, 3651 | "metadata": {}, 3652 | "output_type": "execute_result" 3653 | } 3654 | ], 3655 | "source": [ 3656 | "iris" 3657 | ] 3658 | }, 3659 | { 3660 | "cell_type": "code", 3661 | "execution_count": 108, 3662 | "metadata": { 3663 | "collapsed": false 3664 | }, 3665 | "outputs": [ 3666 | { 3667 | "data": { 3668 | "text/html": [ 3669 | "
§ caslib
\n", 3670 | "
\n", 3671 | "
CASUSER(username)
\n", 3672 | "
\n", 3673 | "

§ tableName
\n", 3674 | "
\n", 3675 | "
_T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4
\n", 3676 | "
\n", 3677 | "

§ rowsTransferred
\n", 3678 | "
\n", 3679 | "
0
\n", 3680 | "
\n", 3681 | "

§ shuffleWaitTime
\n", 3682 | "
\n", 3683 | "
0.0
\n", 3684 | "
\n", 3685 | "

§ minShuffleWaitTime
\n", 3686 | "
\n", 3687 | "
1e+300
\n", 3688 | "
\n", 3689 | "

§ maxShuffleWaitTime
\n", 3690 | "
\n", 3691 | "
0.0
\n", 3692 | "
\n", 3693 | "

§ averageShuffleWaitTime
\n", 3694 | "
\n", 3695 | "
0.0
\n", 3696 | "
\n", 3697 | "

§ casTable
\n", 3698 | "
\n", 3699 | "
CASTable('_T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4', caslib='CASUSER(username)')
\n", 3700 | "
\n", 3701 | "
\n", 3702 | "

elapsed 0.0036s · user 0.002s · sys 0.001s · mem 1.63MB

" 3703 | ], 3704 | "text/plain": [ 3705 | "[caslib]\n", 3706 | "\n", 3707 | " 'CASUSER(username)'\n", 3708 | "\n", 3709 | "[tableName]\n", 3710 | "\n", 3711 | " '_T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4'\n", 3712 | "\n", 3713 | "[rowsTransferred]\n", 3714 | "\n", 3715 | " 0\n", 3716 | "\n", 3717 | "[shuffleWaitTime]\n", 3718 | "\n", 3719 | " 0.0\n", 3720 | "\n", 3721 | "[minShuffleWaitTime]\n", 3722 | "\n", 3723 | " 1e+300\n", 3724 | "\n", 3725 | "[maxShuffleWaitTime]\n", 3726 | "\n", 3727 | " 0.0\n", 3728 | "\n", 3729 | "[averageShuffleWaitTime]\n", 3730 | "\n", 3731 | " 0.0\n", 3732 | "\n", 3733 | "[casTable]\n", 3734 | "\n", 3735 | " CASTable('_T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4', caslib='CASUSER(username)')\n", 3736 | "\n", 3737 | "+ Elapsed: 0.0036s, user: 0.002s, sys: 0.001s, mem: 1.63mb" 3738 | ] 3739 | }, 3740 | "execution_count": 108, 3741 | "metadata": {}, 3742 | "output_type": "execute_result" 3743 | } 3744 | ], 3745 | "source": [ 3746 | "sub_iris = iris.partition()\n", 3747 | "sub_iris" 3748 | ] 3749 | }, 3750 | { 3751 | "cell_type": "code", 3752 | "execution_count": 109, 3753 | "metadata": { 3754 | "collapsed": true 3755 | }, 3756 | "outputs": [], 3757 | "source": [ 3758 | "sub_iris = sub_iris.casTable" 3759 | ] 3760 | }, 3761 | { 3762 | "cell_type": "code", 3763 | "execution_count": 110, 3764 | "metadata": { 3765 | "collapsed": false 3766 | }, 3767 | "outputs": [ 3768 | { 3769 | "data": { 3770 | "text/html": [ 3771 | "
§ Fetch
\n", 3772 | "
\n", 3773 | "
\n", 3774 | "\n", 3775 | " \n", 3776 | " \n", 3777 | " \n", 3778 | " \n", 3779 | " \n", 3780 | " \n", 3781 | " \n", 3782 | " \n", 3783 | " \n", 3784 | " \n", 3785 | " \n", 3786 | " \n", 3787 | " \n", 3788 | " \n", 3789 | " \n", 3790 | " \n", 3791 | " \n", 3792 | " \n", 3793 | " \n", 3794 | " \n", 3795 | " \n", 3796 | " \n", 3797 | " \n", 3798 | " \n", 3799 | " \n", 3800 | " \n", 3801 | " \n", 3802 | " \n", 3803 | " \n", 3804 | " \n", 3805 | " \n", 3806 | " \n", 3807 | " \n", 3808 | " \n", 3809 | " \n", 3810 | " \n", 3811 | " \n", 3812 | " \n", 3813 | " \n", 3814 | " \n", 3815 | " \n", 3816 | " \n", 3817 | " \n", 3818 | " \n", 3819 | " \n", 3820 | " \n", 3821 | " \n", 3822 | " \n", 3823 | " \n", 3824 | " \n", 3825 | " \n", 3826 | " \n", 3827 | " \n", 3828 | " \n", 3829 | " \n", 3830 | " \n", 3831 | " \n", 3832 | " \n", 3833 | " \n", 3834 | " \n", 3835 | " \n", 3836 | " \n", 3837 | " \n", 3838 | " \n", 3839 | " \n", 3840 | " \n", 3841 | " \n", 3842 | " \n", 3843 | " \n", 3844 | " \n", 3845 | " \n", 3846 | " \n", 3847 | " \n", 3848 | " \n", 3849 | " \n", 3850 | " \n", 3851 | " \n", 3852 | " \n", 3853 | " \n", 3854 | " \n", 3855 | " \n", 3856 | " \n", 3857 | " \n", 3858 | " \n", 3859 | " \n", 3860 | " \n", 3861 | " \n", 3862 | " \n", 3863 | " \n", 3864 | " \n", 3865 | " \n", 3866 | " \n", 3867 | " \n", 3868 | " \n", 3869 | " \n", 3870 | " \n", 3871 | " \n", 3872 | " \n", 3873 | " \n", 3874 | " \n", 3875 | " \n", 3876 | " \n", 3877 | " \n", 3878 | " \n", 3879 | " \n", 3880 | " \n", 3881 | " \n", 3882 | " \n", 3883 | " \n", 3884 | " \n", 3885 | " \n", 3886 | " \n", 3887 | " \n", 3888 | " \n", 3889 | " \n", 3890 | " \n", 3891 | " \n", 3892 | " \n", 3893 | " \n", 3894 | " \n", 3895 | " \n", 3896 | " \n", 3897 | " \n", 3898 | " \n", 3899 | " \n", 3900 | " \n", 3901 | " \n", 3902 | " \n", 3903 | " \n", 3904 | " \n", 3905 | " \n", 3906 | " \n", 3907 | "
Selected Rows from Table _T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
06.93.15.42.1virginica
16.93.15.12.3virginica
27.13.05.92.1virginica
37.63.06.62.1virginica
47.32.96.31.8virginica
57.23.66.12.5virginica
67.73.86.72.2virginica
77.72.66.92.3virginica
86.93.25.72.3virginica
97.72.86.72.0virginica
107.23.26.01.8virginica
117.23.05.81.6virginica
127.42.86.11.9virginica
137.93.86.42.0virginica
147.73.06.12.3virginica
\n", 3908 | "
\n", 3909 | "
\n", 3910 | "
\n", 3911 | "

elapsed 0.00331s · user 0.002s · sys 0.001s · mem 1.58MB

" 3912 | ], 3913 | "text/plain": [ 3914 | "[Fetch]\n", 3915 | "\n", 3916 | " Selected Rows from Table _T_RBC6QJBX_6HFJ3SUB_ZDE6BCRWX4\n", 3917 | " \n", 3918 | " sepal_length sepal_width petal_length petal_width species\n", 3919 | " 0 6.9 3.1 5.4 2.1 virginica\n", 3920 | " 1 6.9 3.1 5.1 2.3 virginica\n", 3921 | " 2 7.1 3.0 5.9 2.1 virginica\n", 3922 | " 3 7.6 3.0 6.6 2.1 virginica\n", 3923 | " 4 7.3 2.9 6.3 1.8 virginica\n", 3924 | " 5 7.2 3.6 6.1 2.5 virginica\n", 3925 | " 6 7.7 3.8 6.7 2.2 virginica\n", 3926 | " 7 7.7 2.6 6.9 2.3 virginica\n", 3927 | " 8 6.9 3.2 5.7 2.3 virginica\n", 3928 | " 9 7.7 2.8 6.7 2.0 virginica\n", 3929 | " 10 7.2 3.2 6.0 1.8 virginica\n", 3930 | " 11 7.2 3.0 5.8 1.6 virginica\n", 3931 | " 12 7.4 2.8 6.1 1.9 virginica\n", 3932 | " 13 7.9 3.8 6.4 2.0 virginica\n", 3933 | " 14 7.7 3.0 6.1 2.3 virginica\n", 3934 | "\n", 3935 | "+ Elapsed: 0.00331s, user: 0.002s, sys: 0.001s, mem: 1.58mb" 3936 | ] 3937 | }, 3938 | "execution_count": 110, 3939 | "metadata": {}, 3940 | "output_type": "execute_result" 3941 | } 3942 | ], 3943 | "source": [ 3944 | "sub_iris.fetch()" 3945 | ] 3946 | }, 3947 | { 3948 | "cell_type": "code", 3949 | "execution_count": null, 3950 | "metadata": { 3951 | "collapsed": true 3952 | }, 3953 | "outputs": [], 3954 | "source": [] 3955 | } 3956 | ], 3957 | "metadata": { 3958 | "kernelspec": { 3959 | "display_name": "Python 3", 3960 | "language": "python", 3961 | "name": "python3" 3962 | }, 3963 | "language_info": { 3964 | "codemirror_mode": { 3965 | "name": "ipython", 3966 | "version": 3 3967 | }, 3968 | "file_extension": ".py", 3969 | "mimetype": "text/x-python", 3970 | "name": "python", 3971 | "nbconvert_exporter": "python", 3972 | "pygments_lexer": "ipython3", 3973 | "version": "3.4.5" 3974 | } 3975 | }, 3976 | "nbformat": 4, 3977 | "nbformat_minor": 0 3978 | } 3979 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # SAS Viya: The Python Perspective 4 | 5 | Kevin D Smith & Xiangxiang Meng 6 | 7 | This project contains the sample code for the book *SAS Viya: The Python 8 | Perspective*. All examples are in the form of 9 | [Jupyter notebooks](http://jupyter.org). 10 | 11 | ## Description 12 | 13 | *Learn how to access analytics from SAS Cloud Analytic Services (CAS) 14 | using Python and the SAS® Viya™ platform.* 15 | 16 | SAS® Viya™: The Python Perspective is an introduction to using the 17 | Python client on the SAS Viya platform. SAS Viya is a high-performance, 18 | fault-tolerant analytics architecture that can be deployed on both 19 | public and private cloud infrastructures. While SAS Viya can be used by 20 | various SAS applications, it also enables you to access analytic methods 21 | from SAS, Python, Lua, and Java, as well as through a REST interface 22 | using HTTP or HTTPS. 23 | 24 | This book focuses on the perspective of SAS Viya from Python. SAS Viya 25 | is made up of multiple components. The central piece of this ecosystem 26 | is SAS Cloud Analytic Services (CAS). CAS is the cloud-based server 27 | that all clients communicate with to run analytical methods. The Python 28 | client is used to drive the CAS component directly using objects and 29 | constructs that are familiar to Python programmers. 30 | 31 | Some knowledge of Python would be helpful before using this book; 32 | however, there is an appendix that covers the features of Python that are 33 | used in the CAS Python client. Knowledge of CAS is not required to use 34 | this book. However, you will need to have a CAS server set up and 35 | running to execute the examples in this book. 36 | 37 | With this book, you will learn how to: 38 | 39 | * Install the required components for accessing CAS from Python 40 | * Connect to CAS, load data, and run simple analyses 41 | * Work with CAS using APIs familiar to Python users 42 | * Learn about general CAS workflows and advanced features of the CAS Python client 43 | 44 | SAS® Viya™: The Python Perspective covers topics that will be useful to 45 | beginners as well as experienced CAS users. It includes examples from 46 | creating connections to CAS all the way to simple statistics and machine 47 | learning, but it is also useful as a desktop reference. 48 | 49 | ## Details 50 | 51 | * *Epub* ISBN# 978-1-62960-883-9 52 | * *Mobi* ISBN# 978-1-62960-884-6 53 | * *PDF* ISBN# 978-1-62960-885-3 54 | * *Hardcopy* ISBN# 978-1-62960-276-9 55 | * *Pages* 306 56 | 57 | - [Book Excerpt](https://www.sas.com/storefront/aux/en/splcpython/69194_excerpt.pdf) 58 | - [Table of Contents](https://www.sas.com/storefront/aux/en/splcpython/69194_toc.pdf) 59 | -------------------------------------------------------------------------------- /cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/sas-viya-the-python-perspective/68d1c3363508c0f266cec357fac7ec7fdc1b7ae7/cover.jpg -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # Organics Data Set 2 | 3 | This directory contains the organics data set used in later chapters in 4 | the book. It has been compressed to reduce the download size. To use 5 | it, simply download the file to a location on your CAS server, decompress 6 | it using your favorite ZIP program, and load it into the server using the 7 | `table.loadtable` CAS action. 8 | -------------------------------------------------------------------------------- /data/organics.csv.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/sas-viya-the-python-perspective/68d1c3363508c0f266cec357fac7ec7fdc1b7ae7/data/organics.csv.zip --------------------------------------------------------------------------------