<jupyter_start><jupyter_text>What is Jupyter Notebook?Jupyter notebook is a browser based REPL (read evaluate loop) framework to write python code. It is a great way to start coding quickly and see the results of your code interactively. Whereas software like Sublime or Atom require you to execute code to see what is happening, Jupyter allows you to run code arbitrailtiy which is great for practicing and find bugs in your code.Not only does Jupyter allow you to write Python code however, it also allows coders to add images, math equations, animations or even write Markdown, Javascript and HTML in the window. This allows you to create rich documents that combine Python code, as well as the explanotory text and outputs. It is very popular within the data science community and allows researchers to build off of each others work. CellsJupyter operates through cells. These are the boxes where you write your code or add text or images content. There are three types of cells – code, markdown, and raw. Code is the default and is used to type Python, Markdown is used to add rich text, while raw, for the most part, can be ignored. ModesJupyter has two modes: edit and command mode. Edit mode is when you type content while command mode is where you run cells, add, delete, copy, paste, etc.To run code you can press **ctrl + enter**<jupyter_code>1 + 2
x = 1
x + 9<jupyter_output><empty_output><jupyter_text>--- Variables in PythonA variable in python can be thought of as a bucket to contain data or as a way to attach a name to an object. Attaching a name to an object (or filling a bucket) is done with a simple "=" sign.<jupyter_code>a = 'book'<jupyter_output><empty_output><jupyter_text>In the above example we assign the value 'book' to an object called *a*. Now *a* can be referenced anywhere elsewhere in the code to retrieve it's value.<jupyter_code>print(a)<jupyter_output>book<jupyter_text>Here we used the **print** function to view whats inside of *a*.<jupyter_code>a = 'cover'
a = 'book cover'
a<jupyter_output><empty_output><jupyter_text>Variables are mutable, which means they can be changed simply by assigning new values at any point in the code. In the above example the value of *a* was first changed to 'cover', then to 'book cover', and as Python executes code procedurally from top to bottom, when the print function was made it printed the last value assigned to *a*. --- Data StructuresIf variables are containers to hold values, then data structures can be thought of as the *type* of values variables can take. For example, in the above section on variables, all the values assigned to *a* ('book', 'cover', etc), are words/text – and in Python this is a type of **data structure** called **strings**. This next section will go through a few of the other types of data structures found in Python: lists, dictionaries, sets. ListsLists are perhaps one of the most widely used data structures, particularly for those new to coding. Lists can be thought of as containers to hold multiple values simultaneously.<jupyter_code>a = [1, 5, 7, 100]
print(a)<jupyter_output>[1, 5, 7, 100]<jupyter_text>Lists are created using squared brackets *[]* or via the *list()* function and everything inside a list is separated by commas. Above *a* was assigned four numeric values.<jupyter_code>print(a[0])
print(a[1])<jupyter_output>5<jupyter_text>Lists are structured in a way that makes the values inside easily retrievable later on in code. Items in lists are ordered by indexes, a series of ordered numbers starting from 0. In the above example, putting *[0]* after *a* is a way to access the first element within *a*. If that number was changed to *[1]* it would print the second element in the list assigned to *a*. This operation is known as indexing, as it involves retrieving values based on their order in the list, their index.There are many operations to manipulate the contents of a list. The below example demonstrates how to add items to the end of lists, how to reverse the order of a list, and how to discover the length of a list (the number of items in a list).<jupyter_code># Adding items to a list
a.append(205)
print(a)
# Reversing a lists order
a.reverse()
a
# Getting the number of items in a list
len(a)<jupyter_output><empty_output><jupyter_text>CommentsIn the above code, pound signs () were used to add comments. Comments in Python are parts of the code not executed by the computer. It is usually used by developers to add human readable notes to future readers. DictionariesDictionaries are another data type in Python that are used to hold what are called, key-value pairs. At the simplest level, a key-value pair is just two values, one of which you have designated to be a "key" and the other you have designated to be the "value".<jupyter_code>a = {'building_name': 'Chrysler', 'address': '405 Lexington Av', 'height': 274}<jupyter_output><empty_output><jupyter_text>In this example, we use a dictionary (key-value pairs) to define the attributes of a building – it's address, height, and name. Dictionaries are created using curly brackets *{}* or via the *dict()* function.To retrieve an attribute value is as simple as calling the specific *key*.<jupyter_code>print( a['address'] )<jupyter_output>405 Lexington Av<jupyter_text>You can also combine dictionaries and lists to hold attributes for a collection of objects.<jupyter_code>a = [
  {'building_name': 'Chrysler', 'address': '405 Lexington Av', 'height': 274},
  {'building_name': 'Woolworth', 'address': '233 Broadway', 'height': 241},
  {'building_name': 'Flatiron', 'address': '175 5th Ave', 'height': 86},
]
a[0]['building_name']<jupyter_output><empty_output><jupyter_text>Here we retrieved the building name of the first in the collection Dictionaries also allow for hierarchical (or nested) structuring of data.<jupyter_code>a = {
    'city': 'New York',
    'regions': {
    'counties': ['Kings', 'Bronx', 'Queens', 'Richmond', 'New York']
  }
}
a['regions']['counties']
a['regions']['counties'][1]<jupyter_output><empty_output><jupyter_text>Here the *key* regions is given the value of a dictionary that itself contains a list of counties. ---- OperatorsIf variables are about assigning values to objects and data structures are the various forms said values can take, operators are methods in Python for manipulating those values. Python operators fall into the following categories: mathematical, comparison, logical, identity, bitwise, and sequence. This section covers mathematical, logical and comparison. MathematicalArithmetic operators perform mathematical operations on numbers and symbols. As most of the symbols are familiar to grade school audiences, below are perhaps the less obvious operations.<jupyter_code># Exponentiation: **
4 ** 2
# Modulus: %
3 % 2
# Absolute value: abs()
abs(-10)<jupyter_output><empty_output><jupyter_text>ComparisonAs the name suggests, comparison operators are used to compare two values. Answering questions like: Are these two values the same? Which value is greater of the two? Are these values different?<jupyter_code># Are these values the same: ==
x = 1
y = 2
x == y
# Are these values not the same: !=
x != y
# Greater than or equal to: >=
x >= y
# Less than or equal to: <=
x <= y<jupyter_output><empty_output><jupyter_text>LogicalLogical operators test for truth and check whether specified conditions within a statement have been met. Answering questions like: Are both these statements true?<jupyter_code># Checking whether two statement are true: and
a = 0.5
b = 0.5
x = 1
y = 1
a == b and x == y<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07594103711503027, 'fraction_numerical': 0.008949723611476704, 'mean_word_length': 5.128225806451613, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '457496', 'license': 'CC0-1.0', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2030, 'n_words': 1100, 'path': '_notebooks/jupyter_intro.ipynb', 'repo_name': 'carlobailey/location-intelligence', 'size': '7598'}