<jupyter_start><jupyter_text>Jupyter notebook This Jupyter notebook provides the commands used in the article [Great tip for dynamic data selection using SAS Viya and Python](https://blogs.sas.com/content/sgf/2018/11/06/great-tip-for-dynamic-data-selection-using-sas-viya-and-python/).  Import python packages<jupyter_code>import pandas as pd
import swat<jupyter_output><empty_output><jupyter_text>Connect to the CAS server<jupyter_code>conn = swat.CAS('sasserver.demo.sas.com',8777,'sasdemo','Orion123')<jupyter_output><empty_output><jupyter_text>Check connection<jupyter_code>conn<jupyter_output><empty_output><jupyter_text>Upload data into a DataFrame<jupyter_code>df=conn.upload('https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv')<jupyter_output>NOTE: Cloud Analytic Services made the uploaded file available as table IRIS in caslib CASUSER(sasdemo).
NOTE: The table IRIS has been created in caslib CASUSER(sasdemo) from binary data uploaded to Cloud Analytic Services.<jupyter_text>Load data into a CAS table<jupyter_code>tbl = df.casTable<jupyter_output><empty_output><jupyter_text>Sort the stored values in a variable and change the sort order<jupyter_code>sorttbl = tbl.sort_values(['sepal_length','sepal_width'],
                         ascending=[False,True])<jupyter_output><empty_output><jupyter_text>Expression to create filter and display data<jupyter_code>expr = sorttbl.petal_length > 6.5
newtbl = sorttbl[expr]
newtbl.head()<jupyter_output><empty_output><jupyter_text>Same expression as above writte on one line<jupyter_code>newtbl = sorttbl[sorttbl.petal_length > 6.5]
newtbl.head()<jupyter_output><empty_output><jupyter_text>Another expression to change the filter criteria<jupyter_code>newtbl2 = newtbl[newtbl.petal_width < 2.2]
newtbl2.head()<jupyter_output><empty_output><jupyter_text>Expression to add a bitwise comparison (&) to join the filters<jupyter_code>sorttbl[(sorttbl.petal_length > 6.5) &
        (sorttbl.petal_width < 2.2)].head()<jupyter_output><empty_output><jupyter_text>Display the CASTable object<jupyter_code>sorttbl[(sorttbl.petal_length > 6.5) & 
        (sorttbl.petal_width < 2.2)]<jupyter_output><empty_output><jupyter_text>Expression that includes mathematical operations<jupyter_code>sorttbl[(sorttbl.petal_length + sorttbl.petal_width)
        * 2 > 17.5].head()<jupyter_output><empty_output><jupyter_text>Expression that uses the Python str method to make comparisions on character columns<jupyter_code>sorttbl[sorttbl.species.str.upper().str.startswith('SET')
        ].head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10909090909090909, 'fraction_numerical': 0.014313346228239845, 'mean_word_length': 7.315112540192926, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '245423', 'license': 'Apache-2.0', 'n_tokens_mistral': 932, 'n_tokens_neox': 889, 'n_words': 160, 'path': 'python/blog-notebooks/sasViyaPythonPerspective.ipynb', 'repo_name': 'c964309085/sas-viya-programming', 'size': '2585'}