{ "cells": [ { "cell_type": "markdown", "id": "870b1fe9", "metadata": {}, "source": [ "# pandas: Get specific rows" ] }, { "cell_type": "code", "execution_count": 1, "id": "dd93693f", "metadata": { "execution": { "iopub.execute_input": "2025-09-02T18:58:45.269526Z", "iopub.status.busy": "2025-09-02T18:58:45.269385Z", "iopub.status.idle": "2025-09-02T18:58:45.500112Z", "shell.execute_reply": "2025-09-02T18:58:45.499592Z" }, "tags": [ "hide-output", "scroll-output" ] }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "id": "f0893228", "metadata": {}, "source": [ "## Loading data into Pandas DataFrame\n", "The dataset is from [Kaggle - Pokemon](https://www.kaggle.com/datasets/abcsds/pokemon)." ] }, { "cell_type": "code", "execution_count": 2, "id": "c55bf441", "metadata": { "execution": { "iopub.execute_input": "2025-09-02T18:58:45.501760Z", "iopub.status.busy": "2025-09-02T18:58:45.501586Z", "iopub.status.idle": "2025-09-02T18:58:45.506579Z", "shell.execute_reply": "2025-09-02T18:58:45.506054Z" }, "tags": [ "hide-output", "scroll-output" ] }, "outputs": [], "source": [ "data = pd.read_csv('data/Pokemon.csv')" ] }, { "cell_type": "code", "execution_count": 3, "id": "d77620f5", "metadata": { "execution": { "iopub.execute_input": "2025-09-02T18:58:45.507903Z", "iopub.status.busy": "2025-09-02T18:58:45.507760Z", "iopub.status.idle": "2025-09-02T18:58:45.511086Z", "shell.execute_reply": "2025-09-02T18:58:45.510193Z" }, "tags": [ "hide-output", "scroll-output" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# 1\n", "Name Bulbasaur\n", "Type 1 Grass\n", "Type 2 Poison\n", "Total 318\n", "HP 45\n", "Attack 49\n", "Defense 49\n", "Sp. Atk 65\n", "Sp. Def 65\n", "Speed 45\n", "Generation 1\n", "Legendary False\n", "Name: 0, dtype: object\n" ] } ], "source": [ "# Get the first row, which contains the feature names\n", "middle_row = data.iloc[0]\n", "print(middle_row)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e4bb4d1f", "metadata": { "execution": { "iopub.execute_input": "2025-09-02T18:58:45.512374Z", "iopub.status.busy": "2025-09-02T18:58:45.512248Z", "iopub.status.idle": "2025-09-02T18:58:45.521273Z", "shell.execute_reply": "2025-09-02T18:58:45.520840Z" }, "tags": [ "hide-output", "scroll-output" ] }, "outputs": [ { "data": { "text/html": [ "
\n", " | # | \n", "Name | \n", "Type 1 | \n", "Type 2 | \n", "Total | \n", "HP | \n", "Attack | \n", "Defense | \n", "Sp. Atk | \n", "Sp. Def | \n", "Speed | \n", "Generation | \n", "Legendary | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1 | \n", "Bulbasaur | \n", "Grass | \n", "Poison | \n", "318 | \n", "45 | \n", "49 | \n", "49 | \n", "65 | \n", "65 | \n", "45 | \n", "1 | \n", "False | \n", "
1 | \n", "2 | \n", "Ivysaur | \n", "Grass | \n", "Poison | \n", "405 | \n", "60 | \n", "62 | \n", "63 | \n", "80 | \n", "80 | \n", "60 | \n", "1 | \n", "False | \n", "
2 | \n", "3 | \n", "Venusaur | \n", "Grass | \n", "Poison | \n", "525 | \n", "80 | \n", "82 | \n", "83 | \n", "100 | \n", "100 | \n", "80 | \n", "1 | \n", "False | \n", "
3 | \n", "3 | \n", "VenusaurMega Venusaur | \n", "Grass | \n", "Poison | \n", "625 | \n", "80 | \n", "100 | \n", "123 | \n", "122 | \n", "120 | \n", "80 | \n", "1 | \n", "False | \n", "
4 | \n", "4 | \n", "Charmander | \n", "Fire | \n", "NaN | \n", "309 | \n", "39 | \n", "52 | \n", "43 | \n", "60 | \n", "50 | \n", "65 | \n", "1 | \n", "False | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
795 | \n", "719 | \n", "Diancie | \n", "Rock | \n", "Fairy | \n", "600 | \n", "50 | \n", "100 | \n", "150 | \n", "100 | \n", "150 | \n", "50 | \n", "6 | \n", "True | \n", "
796 | \n", "719 | \n", "DiancieMega Diancie | \n", "Rock | \n", "Fairy | \n", "700 | \n", "50 | \n", "160 | \n", "110 | \n", "160 | \n", "110 | \n", "110 | \n", "6 | \n", "True | \n", "
797 | \n", "720 | \n", "HoopaHoopa Confined | \n", "Psychic | \n", "Ghost | \n", "600 | \n", "80 | \n", "110 | \n", "60 | \n", "150 | \n", "130 | \n", "70 | \n", "6 | \n", "True | \n", "
798 | \n", "720 | \n", "HoopaHoopa Unbound | \n", "Psychic | \n", "Dark | \n", "680 | \n", "80 | \n", "160 | \n", "60 | \n", "170 | \n", "130 | \n", "80 | \n", "6 | \n", "True | \n", "
799 | \n", "721 | \n", "Volcanion | \n", "Fire | \n", "Water | \n", "600 | \n", "80 | \n", "110 | \n", "120 | \n", "130 | \n", "90 | \n", "70 | \n", "6 | \n", "True | \n", "
800 rows × 13 columns
\n", "