{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"toc_visible":true,"authorship_tag":"ABX9TyPFeR+LPGOuhfZGlNrgi/kv"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","metadata":{"id":"DeKRcpe49VnV"},"source":["# Pandas DataFrame UltraQuick Tutorial\n","\n","This Colab introduces [**DataFrames**](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html), which are the central data structure in the pandas API.\n","\n","A DataFrame is similar to an in-memory spreadsheet. Like a spreadsheet:\n","\n","  * A DataFrame stores data in cells.\n","  * A DataFrame has named columns (usually) and numbered rows."]},{"cell_type":"markdown","metadata":{"id":"AByfHsr8H_sU"},"source":["## Import NumPy and pandas modules\n","\n","Run the following code cell to import the NumPy and pandas modules."]},{"cell_type":"code","metadata":{"id":"ZmL0l551Iibq","executionInfo":{"status":"ok","timestamp":1752676168748,"user_tz":-120,"elapsed":663,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}}},"source":["import numpy as np\n","import pandas as pd"],"execution_count":2,"outputs":[]},{"cell_type":"markdown","source":["## Creating a DataFrame"],"metadata":{"id":"pHdaM1g9oyfd"}},{"cell_type":"markdown","source":["The following code creates a DataFrame containing 6 rows and 4 columns. The columns are named \"A\", \"B\", \"C\", and \"D\". The data inside the DataFrame are random numbers (np.random.randn) generated from a standard normal distribution."],"metadata":{"id":"WJ9357Vnn-es"}},{"cell_type":"code","metadata":{"id":"_TU1CPTYJO49","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676319939,"user_tz":-120,"elapsed":13,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"de9f2af5-8be5-42d3-dca2-9ec2f30a59f9"},"source":["df = pd.DataFrame(np.random.randn(6, 4), columns=[\"A\",\"B\",\"C\",\"D\"])\n","print(df)"],"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["          A         B         C         D\n","0  1.774593  1.284493  1.399989  2.017542\n","1  1.100627  0.223671  0.799497  0.371997\n","2 -0.051669 -1.931779  0.775579 -1.294072\n","3 -0.024089  1.322699 -0.004305 -1.025130\n","4  0.295899  0.462191 -2.220017  0.041418\n","5  1.125649 -1.702227  0.410617 -0.549499\n"]}]},{"cell_type":"markdown","metadata":{"id":"tT--iHGjJO5B"},"source":["DataFrames can also be loaded from a .csv file (more extensions are also supported). As you can see, if no column is set as index, pandas creates an \"extra\" column as index."]},{"cell_type":"code","metadata":{"id":"MfDlXD5WJO5C","colab":{"base_uri":"https://localhost:8080/","height":443},"executionInfo":{"status":"ok","timestamp":1752676337026,"user_tz":-120,"elapsed":65,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"2d61a1c6-d3aa-4bf6-e6c0-b96c72ad62a4"},"source":["df = pd.read_csv(\"sample_data/california_housing_test.csv\", sep=',', index_col=None)\n","display(df)"],"execution_count":13,"outputs":[{"output_type":"display_data","data":{"text/plain":["      longitude  latitude  housing_median_age  total_rooms  total_bedrooms  \\\n","0       -122.05     37.37                27.0       3885.0           661.0   \n","1       -118.30     34.26                43.0       1510.0           310.0   \n","2       -117.81     33.78                27.0       3589.0           507.0   \n","3       -118.36     33.82                28.0         67.0            15.0   \n","4       -119.67     36.33                19.0       1241.0           244.0   \n","...         ...       ...                 ...          ...             ...   \n","2995    -119.86     34.42                23.0       1450.0           642.0   \n","2996    -118.14     34.06                27.0       5257.0          1082.0   \n","2997    -119.70     36.30                10.0        956.0           201.0   \n","2998    -117.12     34.10                40.0         96.0            14.0   \n","2999    -119.63     34.42                42.0       1765.0           263.0   \n","\n","      population  households  median_income  median_house_value  \n","0         1537.0       606.0         6.6085            344700.0  \n","1          809.0       277.0         3.5990            176500.0  \n","2         1484.0       495.0         5.7934            270500.0  \n","3           49.0        11.0         6.1359            330000.0  \n","4          850.0       237.0         2.9375             81700.0  \n","...          ...         ...            ...                 ...  \n","2995      1258.0       607.0         1.1790            225000.0  \n","2996      3496.0      1036.0         3.3906            237200.0  \n","2997       693.0       220.0         2.2895             62000.0  \n","2998        46.0        14.0         3.2708            162500.0  \n","2999       753.0       260.0         8.5608            500001.0  \n","\n","[3000 rows x 9 columns]"],"text/html":["\n","  <div id=\"df-de2db4de-7b67-48cc-a85f-1d7b924c4a98\" class=\"colab-df-container\">\n","    <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>longitude</th>\n","      <th>latitude</th>\n","      <th>housing_median_age</th>\n","      <th>total_rooms</th>\n","      <th>total_bedrooms</th>\n","      <th>population</th>\n","      <th>households</th>\n","      <th>median_income</th>\n","      <th>median_house_value</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>-122.05</td>\n","      <td>37.37</td>\n","      <td>27.0</td>\n","      <td>3885.0</td>\n","      <td>661.0</td>\n","      <td>1537.0</td>\n","      <td>606.0</td>\n","      <td>6.6085</td>\n","      <td>344700.0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>-118.30</td>\n","      <td>34.26</td>\n","      <td>43.0</td>\n","      <td>1510.0</td>\n","      <td>310.0</td>\n","      <td>809.0</td>\n","      <td>277.0</td>\n","      <td>3.5990</td>\n","      <td>176500.0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>-117.81</td>\n","      <td>33.78</td>\n","      <td>27.0</td>\n","      <td>3589.0</td>\n","      <td>507.0</td>\n","      <td>1484.0</td>\n","      <td>495.0</td>\n","      <td>5.7934</td>\n","      <td>270500.0</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>-118.36</td>\n","      <td>33.82</td>\n","      <td>28.0</td>\n","      <td>67.0</td>\n","      <td>15.0</td>\n","      <td>49.0</td>\n","      <td>11.0</td>\n","      <td>6.1359</td>\n","      <td>330000.0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>-119.67</td>\n","      <td>36.33</td>\n","      <td>19.0</td>\n","      <td>1241.0</td>\n","      <td>244.0</td>\n","      <td>850.0</td>\n","      <td>237.0</td>\n","      <td>2.9375</td>\n","      <td>81700.0</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>2995</th>\n","      <td>-119.86</td>\n","      <td>34.42</td>\n","      <td>23.0</td>\n","      <td>1450.0</td>\n","      <td>642.0</td>\n","      <td>1258.0</td>\n","      <td>607.0</td>\n","      <td>1.1790</td>\n","      <td>225000.0</td>\n","    </tr>\n","    <tr>\n","      <th>2996</th>\n","      <td>-118.14</td>\n","      <td>34.06</td>\n","      <td>27.0</td>\n","      <td>5257.0</td>\n","      <td>1082.0</td>\n","      <td>3496.0</td>\n","      <td>1036.0</td>\n","      <td>3.3906</td>\n","      <td>237200.0</td>\n","    </tr>\n","    <tr>\n","      <th>2997</th>\n","      <td>-119.70</td>\n","      <td>36.30</td>\n","      <td>10.0</td>\n","      <td>956.0</td>\n","      <td>201.0</td>\n","      <td>693.0</td>\n","      <td>220.0</td>\n","      <td>2.2895</td>\n","      <td>62000.0</td>\n","    </tr>\n","    <tr>\n","      <th>2998</th>\n","      <td>-117.12</td>\n","      <td>34.10</td>\n","      <td>40.0</td>\n","      <td>96.0</td>\n","      <td>14.0</td>\n","      <td>46.0</td>\n","      <td>14.0</td>\n","      <td>3.2708</td>\n","      <td>162500.0</td>\n","    </tr>\n","    <tr>\n","      <th>2999</th>\n","      <td>-119.63</td>\n","      <td>34.42</td>\n","      <td>42.0</td>\n","      <td>1765.0</td>\n","      <td>263.0</td>\n","      <td>753.0</td>\n","      <td>260.0</td>\n","      <td>8.5608</td>\n","      <td>500001.0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>3000 rows × 9 columns</p>\n","</div>\n","    <div class=\"colab-df-buttons\">\n","\n","  <div class=\"colab-df-container\">\n","    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-de2db4de-7b67-48cc-a85f-1d7b924c4a98')\"\n","            title=\"Convert this dataframe to an interactive table.\"\n","            style=\"display:none;\">\n","\n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n","    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n","  </svg>\n","    </button>\n","\n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    .colab-df-buttons div {\n","      margin-bottom: 4px;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","    <script>\n","      const buttonEl =\n","        document.querySelector('#df-de2db4de-7b67-48cc-a85f-1d7b924c4a98 button.colab-df-convert');\n","      buttonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","      async function convertToInteractive(key) {\n","        const element = document.querySelector('#df-de2db4de-7b67-48cc-a85f-1d7b924c4a98');\n","        const dataTable =\n","          await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                    [key], {});\n","        if (!dataTable) return;\n","\n","        const docLinkHtml = 'Like what you see? Visit the ' +\n","          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","          + ' to learn more about interactive tables.';\n","        element.innerHTML = '';\n","        dataTable['output_type'] = 'display_data';\n","        await google.colab.output.renderOutput(dataTable, element);\n","        const docLink = document.createElement('div');\n","        docLink.innerHTML = docLinkHtml;\n","        element.appendChild(docLink);\n","      }\n","    </script>\n","  </div>\n","\n","\n","    <div id=\"df-0333efd8-ee21-4752-961a-a749d622e3fb\">\n","      <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-0333efd8-ee21-4752-961a-a749d622e3fb')\"\n","                title=\"Suggest charts\"\n","                style=\"display:none;\">\n","\n","<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","     width=\"24px\">\n","    <g>\n","        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n","    </g>\n","</svg>\n","      </button>\n","\n","<style>\n","  .colab-df-quickchart {\n","      --bg-color: #E8F0FE;\n","      --fill-color: #1967D2;\n","      --hover-bg-color: #E2EBFA;\n","      --hover-fill-color: #174EA6;\n","      --disabled-fill-color: #AAA;\n","      --disabled-bg-color: #DDD;\n","  }\n","\n","  [theme=dark] .colab-df-quickchart {\n","      --bg-color: #3B4455;\n","      --fill-color: #D2E3FC;\n","      --hover-bg-color: #434B5C;\n","      --hover-fill-color: #FFFFFF;\n","      --disabled-bg-color: #3B4455;\n","      --disabled-fill-color: #666;\n","  }\n","\n","  .colab-df-quickchart {\n","    background-color: var(--bg-color);\n","    border: none;\n","    border-radius: 50%;\n","    cursor: pointer;\n","    display: none;\n","    fill: var(--fill-color);\n","    height: 32px;\n","    padding: 0;\n","    width: 32px;\n","  }\n","\n","  .colab-df-quickchart:hover {\n","    background-color: var(--hover-bg-color);\n","    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n","    fill: var(--button-hover-fill-color);\n","  }\n","\n","  .colab-df-quickchart-complete:disabled,\n","  .colab-df-quickchart-complete:disabled:hover {\n","    background-color: var(--disabled-bg-color);\n","    fill: var(--disabled-fill-color);\n","    box-shadow: none;\n","  }\n","\n","  .colab-df-spinner {\n","    border: 2px solid var(--fill-color);\n","    border-color: transparent;\n","    border-bottom-color: var(--fill-color);\n","    animation:\n","      spin 1s steps(1) infinite;\n","  }\n","\n","  @keyframes spin {\n","    0% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","      border-left-color: var(--fill-color);\n","    }\n","    20% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    30% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","      border-right-color: var(--fill-color);\n","    }\n","    40% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    60% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","    }\n","    80% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-bottom-color: var(--fill-color);\n","    }\n","    90% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","    }\n","  }\n","</style>\n","\n","      <script>\n","        async function quickchart(key) {\n","          const quickchartButtonEl =\n","            document.querySelector('#' + key + ' button');\n","          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n","          quickchartButtonEl.classList.add('colab-df-spinner');\n","          try {\n","            const charts = await google.colab.kernel.invokeFunction(\n","                'suggestCharts', [key], {});\n","          } catch (error) {\n","            console.error('Error during call to suggestCharts:', error);\n","          }\n","          quickchartButtonEl.classList.remove('colab-df-spinner');\n","          quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n","        }\n","        (() => {\n","          let quickchartButtonEl =\n","            document.querySelector('#df-0333efd8-ee21-4752-961a-a749d622e3fb button');\n","          quickchartButtonEl.style.display =\n","            google.colab.kernel.accessAllowed ? 'block' : 'none';\n","        })();\n","      </script>\n","    </div>\n","\n","  <div id=\"id_8b6a1b5a-42b4-47d4-b71b-8f7d9a01dabd\">\n","    <style>\n","      .colab-df-generate {\n","        background-color: #E8F0FE;\n","        border: none;\n","        border-radius: 50%;\n","        cursor: pointer;\n","        display: none;\n","        fill: #1967D2;\n","        height: 32px;\n","        padding: 0 0 0 0;\n","        width: 32px;\n","      }\n","\n","      .colab-df-generate:hover {\n","        background-color: #E2EBFA;\n","        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","        fill: #174EA6;\n","      }\n","\n","      [theme=dark] .colab-df-generate {\n","        background-color: #3B4455;\n","        fill: #D2E3FC;\n","      }\n","\n","      [theme=dark] .colab-df-generate:hover {\n","        background-color: #434B5C;\n","        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","        fill: #FFFFFF;\n","      }\n","    </style>\n","    <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n","            title=\"Generate code using this dataframe.\"\n","            style=\"display:none;\">\n","\n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n","  </svg>\n","    </button>\n","    <script>\n","      (() => {\n","      const buttonEl =\n","        document.querySelector('#id_8b6a1b5a-42b4-47d4-b71b-8f7d9a01dabd button.colab-df-generate');\n","      buttonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","      buttonEl.onclick = () => {\n","        google.colab.notebook.generateWithVariable('df');\n","      }\n","      })();\n","    </script>\n","  </div>\n","\n","    </div>\n","  </div>\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df","summary":"{\n  \"name\": \"df\",\n  \"rows\": 3000,\n  \"fields\": [\n    {\n      \"column\": \"longitude\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1.9949362939550161,\n        \"min\": -124.18,\n        \"max\": -114.49,\n        \"num_unique_values\": 607,\n        \"samples\": [\n          -121.15,\n          -121.46,\n          -121.02\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"latitude\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 2.1296695233438325,\n        \"min\": 32.56,\n        \"max\": 41.92,\n        \"num_unique_values\": 587,\n        \"samples\": [\n          40.17,\n          33.69,\n          39.61\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"housing_median_age\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 12.555395554955755,\n        \"min\": 1.0,\n        \"max\": 52.0,\n        \"num_unique_values\": 52,\n        \"samples\": [\n          14.0,\n          49.0,\n          7.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"total_rooms\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 2155.59333162558,\n        \"min\": 6.0,\n        \"max\": 30450.0,\n        \"num_unique_values\": 2215,\n        \"samples\": [\n          1961.0,\n          1807.0,\n          680.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"total_bedrooms\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 415.6543681363232,\n        \"min\": 2.0,\n        \"max\": 5419.0,\n        \"num_unique_values\": 1055,\n        \"samples\": [\n          532.0,\n          764.0,\n          2162.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"population\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1030.5430124122422,\n        \"min\": 5.0,\n        \"max\": 11935.0,\n        \"num_unique_values\": 1802,\n        \"samples\": [\n          947.0,\n          1140.0,\n          2019.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"households\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 365.42270980552604,\n        \"min\": 2.0,\n        \"max\": 4930.0,\n        \"num_unique_values\": 1026,\n        \"samples\": [\n          646.0,\n          629.0,\n          504.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"median_income\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1.854511729691481,\n        \"min\": 0.4999,\n        \"max\": 15.0001,\n        \"num_unique_values\": 2578,\n        \"samples\": [\n          1.725,\n          0.7403,\n          2.6964\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"median_house_value\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 113119.68746964433,\n        \"min\": 22500.0,\n        \"max\": 500001.0,\n        \"num_unique_values\": 1784,\n        \"samples\": [\n          71900.0,\n          63000.0,\n          115800.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"}},"metadata":{}}]},{"cell_type":"markdown","metadata":{"id":"RutIK84wIp1S"},"source":["The following code cell creates a simple DataFrame containing 10 cells organized as follows:\n","\n","  * 5 rows\n","  * 2 columns, one named `temperature` and the other named `activity`\n","\n","The following code cell instantiates a `pd.DataFrame` class to generate a DataFrame. The class takes two arguments:\n","\n","  * The first argument provides the data to populate the 10 cells. The code cell calls `np.array` to generate the 5x2 NumPy array.\n","  * The second argument identifies the names of the two columns.\n","\n","**Note**: Do not redefine variables in the following code cell. Subsequent code cells use these variables."]},{"cell_type":"code","metadata":{"id":"FNZsPOgSD4F2","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676221630,"user_tz":-120,"elapsed":6,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"b152f9a5-2867-4384-b916-410e5f85fadf"},"source":["# Create and populate a 5x2 NumPy array.\n","my_data = np.array([[0, 3], [10, 7], [20, 9], [30, 14], [40, 15]])\n","\n","# Create a Python list that holds the names of the two columns.\n","my_column_names = ['temperature', 'activity']\n","\n","# Create a DataFrame.\n","my_dataframe = pd.DataFrame(data=my_data, columns=my_column_names)\n","\n","# Print the entire DataFrame\n","print(my_dataframe)"],"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["   temperature  activity\n","0            0         3\n","1           10         7\n","2           20         9\n","3           30        14\n","4           40        15\n"]}]},{"cell_type":"markdown","metadata":{"id":"E_aBVBd0JO5F"},"source":["## Inspecting a dataframe"]},{"cell_type":"markdown","metadata":{"id":"2uSP7WK8JO5F"},"source":["The `head` and `tail` allow you to print the first and last rows of the DataFrame respectively. By default the first and the last five rows are shown, but this number can be defined by the user."]},{"cell_type":"code","metadata":{"id":"hwIWApz4JO5G","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676376959,"user_tz":-120,"elapsed":14,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"1cff598e-c7f6-45d4-9cea-6726833ddf32"},"source":["print(my_dataframe.head())\n","print(my_dataframe.tail())"],"execution_count":14,"outputs":[{"output_type":"stream","name":"stdout","text":["   temperature  activity\n","0            0         3\n","1           10         7\n","2           20         9\n","3           30        14\n","4           40        15\n","   temperature  activity\n","0            0         3\n","1           10         7\n","2           20         9\n","3           30        14\n","4           40        15\n"]}]},{"cell_type":"code","metadata":{"id":"7JaMuwxWJO5I","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676393648,"user_tz":-120,"elapsed":10,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"00a39424-0bc2-487c-e541-9e3ea89c74f5"},"source":["print(my_dataframe.head(2))\n","print(my_dataframe.tail(2))"],"execution_count":17,"outputs":[{"output_type":"stream","name":"stdout","text":["   temperature  activity\n","0            0         3\n","1           10         7\n","   temperature  activity\n","3           30        14\n","4           40        15\n"]}]},{"cell_type":"markdown","metadata":{"id":"u4WrcKIyJO5K"},"source":["A cool way to show DataFrames (but that works only in jupyter) involves using `display`."]},{"cell_type":"code","metadata":{"id":"7Vn5HpQqJO5L","colab":{"base_uri":"https://localhost:8080/","height":206},"executionInfo":{"status":"ok","timestamp":1752676397703,"user_tz":-120,"elapsed":12,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"a5f852b3-99ca-491f-8331-d32e6d3dec8f"},"source":["display(my_dataframe)"],"execution_count":18,"outputs":[{"output_type":"display_data","data":{"text/plain":["   temperature  activity\n","0            0         3\n","1           10         7\n","2           20         9\n","3           30        14\n","4           40        15"],"text/html":["\n","  <div id=\"df-e6b38a61-4fe1-4360-b670-f8c975c007eb\" class=\"colab-df-container\">\n","    <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>temperature</th>\n","      <th>activity</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>0</td>\n","      <td>3</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>10</td>\n","      <td>7</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>20</td>\n","      <td>9</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>30</td>\n","      <td>14</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>40</td>\n","      <td>15</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","    <div class=\"colab-df-buttons\">\n","\n","  <div class=\"colab-df-container\">\n","    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e6b38a61-4fe1-4360-b670-f8c975c007eb')\"\n","            title=\"Convert this dataframe to an interactive table.\"\n","            style=\"display:none;\">\n","\n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n","    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n","  </svg>\n","    </button>\n","\n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    .colab-df-buttons div {\n","      margin-bottom: 4px;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","    <script>\n","      const buttonEl =\n","        document.querySelector('#df-e6b38a61-4fe1-4360-b670-f8c975c007eb button.colab-df-convert');\n","      buttonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","      async function convertToInteractive(key) {\n","        const element = document.querySelector('#df-e6b38a61-4fe1-4360-b670-f8c975c007eb');\n","        const dataTable =\n","          await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                    [key], {});\n","        if (!dataTable) return;\n","\n","        const docLinkHtml = 'Like what you see? Visit the ' +\n","          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","          + ' to learn more about interactive tables.';\n","        element.innerHTML = '';\n","        dataTable['output_type'] = 'display_data';\n","        await google.colab.output.renderOutput(dataTable, element);\n","        const docLink = document.createElement('div');\n","        docLink.innerHTML = docLinkHtml;\n","        element.appendChild(docLink);\n","      }\n","    </script>\n","  </div>\n","\n","\n","    <div id=\"df-ce4f05a8-4625-448a-bbd5-26af20431f3c\">\n","      <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-ce4f05a8-4625-448a-bbd5-26af20431f3c')\"\n","                title=\"Suggest charts\"\n","                style=\"display:none;\">\n","\n","<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","     width=\"24px\">\n","    <g>\n","        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n","    </g>\n","</svg>\n","      </button>\n","\n","<style>\n","  .colab-df-quickchart {\n","      --bg-color: #E8F0FE;\n","      --fill-color: #1967D2;\n","      --hover-bg-color: #E2EBFA;\n","      --hover-fill-color: #174EA6;\n","      --disabled-fill-color: #AAA;\n","      --disabled-bg-color: #DDD;\n","  }\n","\n","  [theme=dark] .colab-df-quickchart {\n","      --bg-color: #3B4455;\n","      --fill-color: #D2E3FC;\n","      --hover-bg-color: #434B5C;\n","      --hover-fill-color: #FFFFFF;\n","      --disabled-bg-color: #3B4455;\n","      --disabled-fill-color: #666;\n","  }\n","\n","  .colab-df-quickchart {\n","    background-color: var(--bg-color);\n","    border: none;\n","    border-radius: 50%;\n","    cursor: pointer;\n","    display: none;\n","    fill: var(--fill-color);\n","    height: 32px;\n","    padding: 0;\n","    width: 32px;\n","  }\n","\n","  .colab-df-quickchart:hover {\n","    background-color: var(--hover-bg-color);\n","    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n","    fill: var(--button-hover-fill-color);\n","  }\n","\n","  .colab-df-quickchart-complete:disabled,\n","  .colab-df-quickchart-complete:disabled:hover {\n","    background-color: var(--disabled-bg-color);\n","    fill: var(--disabled-fill-color);\n","    box-shadow: none;\n","  }\n","\n","  .colab-df-spinner {\n","    border: 2px solid var(--fill-color);\n","    border-color: transparent;\n","    border-bottom-color: var(--fill-color);\n","    animation:\n","      spin 1s steps(1) infinite;\n","  }\n","\n","  @keyframes spin {\n","    0% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","      border-left-color: var(--fill-color);\n","    }\n","    20% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    30% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","      border-right-color: var(--fill-color);\n","    }\n","    40% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    60% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","    }\n","    80% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-bottom-color: var(--fill-color);\n","    }\n","    90% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","    }\n","  }\n","</style>\n","\n","      <script>\n","        async function quickchart(key) {\n","          const quickchartButtonEl =\n","            document.querySelector('#' + key + ' button');\n","          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n","          quickchartButtonEl.classList.add('colab-df-spinner');\n","          try {\n","            const charts = await google.colab.kernel.invokeFunction(\n","                'suggestCharts', [key], {});\n","          } catch (error) {\n","            console.error('Error during call to suggestCharts:', error);\n","          }\n","          quickchartButtonEl.classList.remove('colab-df-spinner');\n","          quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n","        }\n","        (() => {\n","          let quickchartButtonEl =\n","            document.querySelector('#df-ce4f05a8-4625-448a-bbd5-26af20431f3c button');\n","          quickchartButtonEl.style.display =\n","            google.colab.kernel.accessAllowed ? 'block' : 'none';\n","        })();\n","      </script>\n","    </div>\n","\n","  <div id=\"id_fcb6f973-5a3e-4e6e-b691-6ac5d973a4db\">\n","    <style>\n","      .colab-df-generate {\n","        background-color: #E8F0FE;\n","        border: none;\n","        border-radius: 50%;\n","        cursor: pointer;\n","        display: none;\n","        fill: #1967D2;\n","        height: 32px;\n","        padding: 0 0 0 0;\n","        width: 32px;\n","      }\n","\n","      .colab-df-generate:hover {\n","        background-color: #E2EBFA;\n","        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","        fill: #174EA6;\n","      }\n","\n","      [theme=dark] .colab-df-generate {\n","        background-color: #3B4455;\n","        fill: #D2E3FC;\n","      }\n","\n","      [theme=dark] .colab-df-generate:hover {\n","        background-color: #434B5C;\n","        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","        fill: #FFFFFF;\n","      }\n","    </style>\n","    <button class=\"colab-df-generate\" onclick=\"generateWithVariable('my_dataframe')\"\n","            title=\"Generate code using this dataframe.\"\n","            style=\"display:none;\">\n","\n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n","  </svg>\n","    </button>\n","    <script>\n","      (() => {\n","      const buttonEl =\n","        document.querySelector('#id_fcb6f973-5a3e-4e6e-b691-6ac5d973a4db button.colab-df-generate');\n","      buttonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","      buttonEl.onclick = () => {\n","        google.colab.notebook.generateWithVariable('my_dataframe');\n","      }\n","      })();\n","    </script>\n","  </div>\n","\n","    </div>\n","  </div>\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"my_dataframe","summary":"{\n  \"name\": \"my_dataframe\",\n  \"rows\": 5,\n  \"fields\": [\n    {\n      \"column\": \"temperature\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 15,\n        \"min\": 0,\n        \"max\": 40,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          10,\n          40,\n          20\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"activity\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 4,\n        \"min\": 3,\n        \"max\": 15,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          7,\n          15,\n          9\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"}},"metadata":{}}]},{"cell_type":"markdown","metadata":{"id":"NJ-I78_7OFVs"},"source":["## Adding a new column to a DataFrame\n","\n","You may add a new column to an existing pandas DataFrame just by assigning values to a new column name. For example, the following code creates a third column named `adjusted` in `my_dataframe`:"]},{"cell_type":"code","metadata":{"id":"JEBZyMdEOngx","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676404110,"user_tz":-120,"elapsed":8,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"ca0dd22a-8ea7-4c55-a980-b4634913c896"},"source":["# Create a new column named adjusted.\n","my_dataframe[\"adjusted\"] = my_dataframe[\"activity\"] + 2\n","\n","# Print the entire DataFrame\n","print(my_dataframe)"],"execution_count":19,"outputs":[{"output_type":"stream","name":"stdout","text":["   temperature  activity  adjusted\n","0            0         3         5\n","1           10         7         9\n","2           20         9        11\n","3           30        14        16\n","4           40        15        17\n"]}]},{"cell_type":"markdown","metadata":{"id":"RJ2aziCR5th2"},"source":["## Specifying a subset of a DataFrame\n","\n","Pandas provide multiples ways to isolate specific rows, columns, slices or cells in a DataFrame."]},{"cell_type":"code","source":["print(\"Rows #0, #1, and #2:\\n\")\n","print(my_dataframe.head(3), '\\n')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"bqMkKMhOqRMl","executionInfo":{"status":"ok","timestamp":1752676670767,"user_tz":-120,"elapsed":22,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"09db5816-95fb-4151-fc75-4ae0162455d5"},"execution_count":31,"outputs":[{"output_type":"stream","name":"stdout","text":["Rows #0, #1, and #2:\n","\n","   temperature  activity  adjusted\n","0            0         3         5\n","1           10         7         9\n","2           20         9        11 \n","\n"]}]},{"cell_type":"code","source":["print(\"Row #2:\\n\")\n","print(my_dataframe.iloc[[2]], '\\n')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"yKG6stXZqTXF","executionInfo":{"status":"ok","timestamp":1752676671269,"user_tz":-120,"elapsed":13,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"186a3fe1-2e90-4693-d862-c294338bf250"},"execution_count":32,"outputs":[{"output_type":"stream","name":"stdout","text":["Row #2:\n","\n","   temperature  activity  adjusted\n","2           20         9        11 \n","\n"]}]},{"cell_type":"code","source":["print(\"Rows #1, #2, and #3:\\n\")\n","print(my_dataframe[1:4], '\\n')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"MQac5GEBqUt1","executionInfo":{"status":"ok","timestamp":1752676671833,"user_tz":-120,"elapsed":5,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"11a986c2-161e-4c0f-f769-aeb0c807de98"},"execution_count":33,"outputs":[{"output_type":"stream","name":"stdout","text":["Rows #1, #2, and #3:\n","\n","   temperature  activity  adjusted\n","1           10         7         9\n","2           20         9        11\n","3           30        14        16 \n","\n"]}]},{"cell_type":"code","source":["print(\"Column 'temperature':\\n\")\n","print(my_dataframe['temperature'])\n","print(\"Alternative way:\\n\")\n","print(my_dataframe.temperature)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"N3KXMNr-qWHV","executionInfo":{"status":"ok","timestamp":1752676672379,"user_tz":-120,"elapsed":3,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"a482ea86-0f65-41b4-a707-d3f071c6d2e9"},"execution_count":34,"outputs":[{"output_type":"stream","name":"stdout","text":["Column 'temperature':\n","\n","0     0\n","1    10\n","2    20\n","3    30\n","4    40\n","Name: temperature, dtype: int64\n","Alternative way:\n","\n","0     0\n","1    10\n","2    20\n","3    30\n","4    40\n","Name: temperature, dtype: int64\n"]}]},{"cell_type":"code","metadata":{"id":"RIO91Fu65s6k","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676673568,"user_tz":-120,"elapsed":8,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"12cbc54a-e7ba-42df-f535-1a064cb107fe"},"source":["print(\"Columns 'temperature' and 'adjusted':\\n\")\n","print(my_dataframe[['temperature', 'adjusted']])"],"execution_count":35,"outputs":[{"output_type":"stream","name":"stdout","text":["Columns 'temperature' and 'adjusted':\n","\n","   temperature  adjusted\n","0            0         5\n","1           10         9\n","2           20        11\n","3           30        16\n","4           40        17\n"]}]},{"cell_type":"code","source":["print(\"Rows where the 'temperature' is greated than 20\\n\")\n","print(my_dataframe[my_dataframe.temperature > 20])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"w8tbBBzMqgId","executionInfo":{"status":"ok","timestamp":1752676674214,"user_tz":-120,"elapsed":4,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"35e6dade-2892-411b-ff6f-1fbee5b3db09"},"execution_count":36,"outputs":[{"output_type":"stream","name":"stdout","text":["Rows where the 'temperature' is greated than 20\n","\n","   temperature  activity  adjusted\n","3           30        14        16\n","4           40        15        17\n"]}]},{"cell_type":"markdown","metadata":{"id":"_cL_NxAdZzdS"},"source":["## Task 1: Create a DataFrame\n","\n","Do the following:\n","\n","  1. Create an 3x4 (3 rows x 4 columns) pandas DataFrame in which the columns are named `Eleanor`,  `Chidi`, `Tahani`, and `Jason`.  Populate each of the 12 cells in the DataFrame with a random integer between 0 and 100, inclusive.\n","\n","  2. Output the following:\n","\n","     * the entire DataFrame\n","     * the value in the cell of row #1 of the `Eleanor` column\n","\n","  3. Create a fifth column named `Janet`, which is populated with the row-by-row sums of `Tahani` and `Jason`.\n"]},{"cell_type":"code","metadata":{"id":"cIJEv08DMSxj","executionInfo":{"status":"ok","timestamp":1752676678183,"user_tz":-120,"elapsed":1,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}}},"source":["# Write your code here."],"execution_count":37,"outputs":[]},{"cell_type":"code","metadata":{"id":"dPmpVM_8IoBO","cellView":"form","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1752676679068,"user_tz":-120,"elapsed":19,"user":{"displayName":"Beatrice Portelli","userId":"14323252246116225690"}},"outputId":"99e4ec90-8832-49f1-c4b9-9c7f12ecc484"},"source":["#@title Double-click for a solution to Task 1.\n","\n","# Create a Python list that holds the names of the four columns.\n","my_column_names = ['Eleanor', 'Chidi', 'Tahani', 'Jason']\n","\n","# Create a 3x4 numpy array, each cell populated with a random integer.\n","my_data = np.random.randint(low=0, high=101, size=(3, 4))\n","\n","# Create a DataFrame.\n","df = pd.DataFrame(data=my_data, columns=my_column_names)\n","\n","# Print the entire DataFrame\n","print(df)\n","\n","# Print the value in row #1 of the Eleanor column.\n","print(\"\\nSecond row of the Eleanor column: %d\\n\" % df['Eleanor'][1])\n","\n","# Create a column named Janet whose contents are the sum\n","# of two other columns.\n","df['Janet'] = df['Tahani'] + df['Jason']\n","\n","# Print the enhanced DataFrame\n","print(df)"],"execution_count":38,"outputs":[{"output_type":"stream","name":"stdout","text":["   Eleanor  Chidi  Tahani  Jason\n","0       38     81      46     79\n","1       38     78      88     35\n","2       61      4      59     27\n","\n","Second row of the Eleanor column: 38\n","\n","   Eleanor  Chidi  Tahani  Jason  Janet\n","0       38     81      46     79    125\n","1       38     78      88     35    123\n","2       61      4      59     27     86\n"]}]},{"cell_type":"markdown","metadata":{"id":"dOvc1AXrJO5e"},"source":["This brief overview has touched on many of the important things that you need to know about pandas, but is far from complete. Check out the [pandas reference](https://pandas.pydata.org/pandas-docs/stable/index.html) or the [10 minutes to pandas tutorial](https://pandas.pydata.org/pandas-docs/stable/10min.html) to find out much more about pandas."]}]}