{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "pandas-select-columns.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "sBn4_vrWHjCi", "colab_type": "text" }, "source": [ "# **Introduction to Pandas dataframe: Select specific column(s) in a DataFrame**\n", "\n", "Chanin Nantasenamat\n", "\n", "[*'Data Professor' YouTube channel*](http://youtube.com/dataprofessor)\n", "\n", "In this Jupyter notebook, I will be showing you how to select specifc column(s) in a DataFrame.\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": { "id": "PBWDV57tHmLf", "colab_type": "text" }, "source": [ "## **Download CSV data**" ] }, { "cell_type": "code", "metadata": { "id": "pq6EVr5sHXAq", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 208 }, "outputId": "1eea0330-050d-4101-c21b-dce27e09cf01" }, "source": [ "! wget https://raw.githubusercontent.com/dataprofessor/data/master/delaney_solubility_with_descriptors.csv" ], "execution_count": 10, "outputs": [ { "output_type": "stream", "text": [ "--2020-05-03 17:41:00-- https://raw.githubusercontent.com/dataprofessor/data/master/delaney_solubility_with_descriptors.csv\n", "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n", "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 57370 (56K) [text/plain]\n", "Saving to: ‘delaney_solubility_with_descriptors.csv’\n", "\n", "\r delaney_s 0%[ ] 0 --.-KB/s \rdelaney_solubility_ 100%[===================>] 56.03K --.-KB/s in 0.01s \n", "\n", "2020-05-03 17:41:00 (3.82 MB/s) - ‘delaney_solubility_with_descriptors.csv’ saved [57370/57370]\n", "\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "qJ9j-V_zHwm8", "colab_type": "code", "colab": {} }, "source": [ "import pandas as pd" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "D6twMV5THz2r", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 415 }, "outputId": "3230bda2-d61e-48f6-f232-0dabecc08908" }, "source": [ "df = pd.read_csv('delaney_solubility_with_descriptors.csv')\n", "df" ], "execution_count": 12, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
| \n", " | MolLogP | \n", "MolWt | \n", "NumRotatableBonds | \n", "AromaticProportion | \n", "logS | \n", "
|---|---|---|---|---|---|
| 0 | \n", "2.59540 | \n", "167.850 | \n", "0.0 | \n", "0.000000 | \n", "-2.180 | \n", "
| 1 | \n", "2.37650 | \n", "133.405 | \n", "0.0 | \n", "0.000000 | \n", "-2.000 | \n", "
| 2 | \n", "2.59380 | \n", "167.850 | \n", "1.0 | \n", "0.000000 | \n", "-1.740 | \n", "
| 3 | \n", "2.02890 | \n", "133.405 | \n", "1.0 | \n", "0.000000 | \n", "-1.480 | \n", "
| 4 | \n", "2.91890 | \n", "187.375 | \n", "1.0 | \n", "0.000000 | \n", "-3.040 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 1139 | \n", "1.98820 | \n", "287.343 | \n", "8.0 | \n", "0.000000 | \n", "1.144 | \n", "
| 1140 | \n", "3.42130 | \n", "286.114 | \n", "2.0 | \n", "0.333333 | \n", "-4.925 | \n", "
| 1141 | \n", "3.60960 | \n", "308.333 | \n", "4.0 | \n", "0.695652 | \n", "-3.893 | \n", "
| 1142 | \n", "2.56214 | \n", "354.815 | \n", "3.0 | \n", "0.521739 | \n", "-3.790 | \n", "
| 1143 | \n", "2.02164 | \n", "179.219 | \n", "1.0 | \n", "0.461538 | \n", "-2.581 | \n", "
1144 rows × 5 columns
\n", "| \n", " | MolLogP | \n", "NumRotatableBonds | \n", "
|---|---|---|
| 0 | \n", "2.59540 | \n", "0.0 | \n", "
| 1 | \n", "2.37650 | \n", "0.0 | \n", "
| 2 | \n", "2.59380 | \n", "1.0 | \n", "
| 3 | \n", "2.02890 | \n", "1.0 | \n", "
| 4 | \n", "2.91890 | \n", "1.0 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 1139 | \n", "1.98820 | \n", "8.0 | \n", "
| 1140 | \n", "3.42130 | \n", "2.0 | \n", "
| 1141 | \n", "3.60960 | \n", "4.0 | \n", "
| 1142 | \n", "2.56214 | \n", "3.0 | \n", "
| 1143 | \n", "2.02164 | \n", "1.0 | \n", "
1144 rows × 2 columns
\n", "| \n", " | MolLogP | \n", "NumRotatableBonds | \n", "
|---|---|---|
| 0 | \n", "2.59540 | \n", "0.0 | \n", "
| 1 | \n", "2.37650 | \n", "0.0 | \n", "
| 2 | \n", "2.59380 | \n", "1.0 | \n", "
| 3 | \n", "2.02890 | \n", "1.0 | \n", "
| 4 | \n", "2.91890 | \n", "1.0 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 1139 | \n", "1.98820 | \n", "8.0 | \n", "
| 1140 | \n", "3.42130 | \n", "2.0 | \n", "
| 1141 | \n", "3.60960 | \n", "4.0 | \n", "
| 1142 | \n", "2.56214 | \n", "3.0 | \n", "
| 1143 | \n", "2.02164 | \n", "1.0 | \n", "
1144 rows × 2 columns
\n", "| \n", " | MolLogP | \n", "NumRotatableBonds | \n", "logS | \n", "
|---|---|---|---|
| 0 | \n", "2.59540 | \n", "0.0 | \n", "-2.180 | \n", "
| 1 | \n", "2.37650 | \n", "0.0 | \n", "-2.000 | \n", "
| 2 | \n", "2.59380 | \n", "1.0 | \n", "-1.740 | \n", "
| 3 | \n", "2.02890 | \n", "1.0 | \n", "-1.480 | \n", "
| 4 | \n", "2.91890 | \n", "1.0 | \n", "-3.040 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "
| 1139 | \n", "1.98820 | \n", "8.0 | \n", "1.144 | \n", "
| 1140 | \n", "3.42130 | \n", "2.0 | \n", "-4.925 | \n", "
| 1141 | \n", "3.60960 | \n", "4.0 | \n", "-3.893 | \n", "
| 1142 | \n", "2.56214 | \n", "3.0 | \n", "-3.790 | \n", "
| 1143 | \n", "2.02164 | \n", "1.0 | \n", "-2.581 | \n", "
1144 rows × 3 columns
\n", "