<jupyter_start><jupyter_text>An Introduction to Python In this lesson we will learn how to work with arthritis inflammation datasets in Python. However,before we discuss how to deal with many data points, let's learn how to work withsingle data values.  VariablesAny Python interpreter can be used as a calculator:<jupyter_code>print ("AHH!!!!!!!!!!")<jupyter_output>AHH!!!!!!!!!!<jupyter_text>This is great but not very interesting. To do anything useful with data, we needto assign its value to a _variable_. In Python, we can assign a value to avariable, using the equals sign `=`. For example, to assign value `60` to avariable `weight_kg`, we would execute:<jupyter_code>weight_kg=500.0
print (weight_kg)<jupyter_output>500.0<jupyter_text>From now on, whenever we use `weight_kg`, Python will substitute the value we assigned toit. In essence, **a variable is just a name for a value**.In Python, variable names: - can include letters, digits, and underscores - cannot start with a digit - are case sensitive.This means that, for example: - `weight0` is a valid variable name, whereas `0weight` is not - `weight` and `Weight` are different variables  Types of dataPython knows various types of data. Three common ones are:* integer numbers* floating point numbers, and* strings.In the example above, variable `weight_kg` has an integer value of `60`.To create a variable with a floating point value, we can execute:<jupyter_code>weight_text="Weight in kilos"<jupyter_output><empty_output><jupyter_text>And to create a string we simply have to add single or double quotes around some text, for example:  Using Variables in PythonTo display the value of a variable to the screen in Python, we can use the `print` function:<jupyter_code>print(weight_text,weight_kg)<jupyter_output>Weight in kilos 500.0<jupyter_text>We can display multiple things at once using only one `print` command: Moreover, we can do arithmetics with variables right inside the `print` function:<jupyter_code>print(weight_kg*67435.0)<jupyter_output>33717500.0<jupyter_text>The above command, however, did not change the value of `weight_kg`: To change the value of the `weight_kg` variable, we have to**assign** `weight_kg` a new value using the equals `=` sign:<jupyter_code>weight_kg=607<jupyter_output><empty_output><jupyter_text>Variables as Sticky NotesA variable is analogous to a sticky note with a name written on it:assigning a value to a variable is like putting that sticky note on a particular value.![Variables as Sticky Notes](./python-sticky-note-variables-01.svg)This means that assigning a value to one variable does **not** change the values of other variables.For example, let's store the subject's weight in pounds in its own variable: ![Creating Another Variable](./python-sticky-note-variables-02.svg)Let's now change `weight_kg`: ![Updating a Variable](./python-sticky-note-variables-03.svg)Since `weight_lb` doesn't remember where its value came from,it isn't automatically updated when `weight_kg` changes. Words are useful, but what's more useful are the sentences and stories we buildwith them. Similarly, while a lot of powerful, general tools are built intolanguages like Python, specialized tools built up from these basic units live inlibraries that can be called upon when needed.  Loading data into PythonIn order to load our inflammation data, we need to access(import in Python terminology) a library called[NumPy](http://docs.scipy.org/doc/numpy/ "NumPy Documentation").  In general you should use thislibrary if you want to do fancy things with numbers, especially if you have matrices or arrays.  Wecan import NumPy using:<jupyter_code>import numpy<jupyter_output><empty_output><jupyter_text>Importing a library is like getting a piece of lab equipment out of a storage locker and setting itup on the bench. Libraries provide additional functionality to the basic Python package, much likea new piece of equipment adds functionality to a lab space. Just like in the lab, importing toomany libraries can sometimes complicate and slow down your programs - so we only import what weneed for each program. Once we've imported the library, we can ask the library to read our datafile for us: The expression `numpy.loadtxt(...)` is a function call that asks Python to runthe function `loadtxt` which belongs to the `numpy` library. This dottednotation is used everywhere in Python: the thing that appears before the dotcontains the thing that appears after.As an example, John Smith is the John that belongs to the Smith family. We coulduse the dot notation to write his name `smith.john`, just as `loadtxt` is afunction that belongs to the `numpy` library.`numpy.loadtxt` has two parameters: the name of the file we want to read and thedelimiter that separates values on a line. These both need to be characterstrings (or strings for short), so we put them in quotes.Since we haven't told it to do anything else with the function's output,the notebook displays it.In this case,that output is the data we just loaded.By default,only a few rows and columns are shown(with `...` to omit elements when displaying big arrays). To save space, Pythondisplays numbers as `1.` instead of `1.0`when there's nothing interesting after the decimal point.Our call to `numpy.loadtxt` read our filebut didn't save the data in memory.To do that,we need to assign the array to a variable. Just as we can assign a single value to a variable, wecan also assign an array of values to a variable using the same syntax.  Let's re-run`numpy.loadtxt` and save the returned data:<jupyter_code>!l
numpy.loadtxt("inflammation-01.csv", delimiter=",")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06767980208517406, 'fraction_numerical': 0.008305354302880368, 'mean_word_length': 5.417233560090703, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '658611', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1471, 'n_words': 777, 'path': '03-fundamentals-of-python/01-introduction-to-python.ipynb', 'repo_name': 'TaraAthem/rcsc18_lessons', 'size': '5659'}