<jupyter_start><jupyter_text>**Welcome to your first lab's cheatsheet** 💫Things we will cover: - Recap on Python Lists- Recap on NumPy Before we get to our tasks, let's review `Python lists` and `NumPy`.  1 Python Lists : Review & Cheatsheet **How do I identify a list?** When you see square brackets with items or elements seperated with commas.<jupyter_code>bmi = [22.4, 40, 29.3, 21.5, 29.9, 30.4]<jupyter_output><empty_output><jupyter_text>1.1 Indexing Each item in a Python list takes a special position called `index` As you can see below, we have both negative and positive indexing. ![indexing1.png](attachment:indexing1.png) Example:<jupyter_code>bmi[3]
bmi[-1]<jupyter_output><empty_output><jupyter_text>1.2 Slicing Slicing includes the **start point** up to (but not including) the **end point**  The general rule looks like this:  `bmi[StartAt : EndBefore]` If we want the elements from index 2 to 5, (index 5 not included) :<jupyter_code>bmi[2:5]<jupyter_output><empty_output><jupyter_text>Sometimes we want to skip some elements while slicing a list. The rules of the start and end point are the same, but we can add a step parameter at the end. PS : The default is always `1` `bmi[StartAt : EndBefore : Step]`<jupyter_code>bmi[0:6:2]<jupyter_output><empty_output><jupyter_text>1.4 Useful List Methods & Built-in Functions - **Append ( )** -> Adds a single element to a list - **Extend( )** -> Adds every each element to a list  - **Sort( )** -> Sorts a list in an ascending order - **index( x )** -> returns the lowest index where element x appears. - **pop( )** - **min(list)**- **max(list)**  2 NumPy : Review & Cheatsheet **Wait... why am I learning this again? I already know lists!** Untill now, we all know Python lists are powerful!    They can hold collection of values    They can hold different types of data    We can change, add or remove the items inside of a list    buttttt one important thing is missing. **the ability to perform a mathematical operation over *all* the items at the same time**<jupyter_code>heights = [1.73, 1.68, 1.79, 1.92, 1.50, 1.64]
weights = [90.0, 71.0, 55.0, 67.0, 99.2, 69]<jupyter_output><empty_output><jupyter_text>[in case you haven't installed numpy, run the following cell]<jupyter_code>!pip3 install numpy
import numpy as np<jupyter_output><empty_output><jupyter_text>2.1 Converting a list into an Ndarray<jupyter_code>heights_np = np.array(heights)
weights_np = np.array(weights)<jupyter_output><empty_output><jupyter_text>Performing a mathematical operation over every item in an array<jupyter_code>weights_np/heights_np**2<jupyter_output><empty_output><jupyter_text>2.2 Sum of two numpy arrays<jupyter_code>weights_np + heights_np<jupyter_output><empty_output><jupyter_text>2.3 Numpy Array Subsetting<jupyter_code>weights_np[3]<jupyter_output><empty_output><jupyter_text>2.4 Useful stuff we can do with numpy arrays - np.mean()- np.std()- np.arrange()- np.transpose() -> switches rows and columns***- np.shape- np.size  2.5 2-D Arrays Usually our data is made up of **columns** and **rows**, meaning our data is *multidimensional*<jupyter_code>months = [1, 2, 3]
expenses = [738.11, 837.81, 738.91] #in GEL
expenses_array = np.array([months, expenses])
expenses_array<jupyter_output><empty_output><jupyter_text>Question : Wait how do we index our array now??! **array[row_index, column_index]**<jupyter_code>expenses_array[1, 2]<jupyter_output><empty_output><jupyter_text>As you can see, we selected the item in the second row, and column 3. ✨How do we select a whole column or row?<jupyter_code>expenses_array[:, 2]
expenses_array[1, :]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11560693641618497, 'fraction_numerical': 0.030278007156619872, 'mean_word_length': 5.667889908256881, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 58, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '629541', 'license': 'MIT', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1227, 'n_words': 416, 'path': 'lab1/Lab1cheatsheat.ipynb', 'repo_name': 'negarvahid/data-analysis', 'size': '3633'}