From f3da7d4cfd1237d49a13e8f850c969cc7c31569e Mon Sep 17 00:00:00 2001 From: "floydnbrooks@gmail.comgit config --global user.email" Date: Tue, 9 Jul 2024 14:16:38 -0400 Subject: [PATCH 1/2] added .squeeze() method as the squeeze = bool has been deprecated. Also, the time format in respected areas. --- .../files/Lecture.ipynb | 353 +++++++++++------- .../files/out.csv | 4 + 2 files changed, 231 insertions(+), 126 deletions(-) create mode 100644 unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/out.csv diff --git a/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb index 44de965..b8de3f7 100644 --- a/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb +++ b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb @@ -2,7 +2,9 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ "![rmotr](https://user-images.githubusercontent.com/7065401/52071918-bda15380-2562-11e9-828c-7f95297e4a82.png)\n", "
\n", @@ -28,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ @@ -54,14 +56,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 68, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "<_io.TextIOWrapper name='btc-market-price.csv' mode='r' encoding='UTF-8'>\n" + "<_io.TextIOWrapper name='btc-market-price.csv' mode='r' encoding='cp1252'>\n" ] } ], @@ -81,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 71, "metadata": {}, "outputs": [ { @@ -201,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 77, "metadata": {}, "outputs": [ { @@ -280,7 +282,7 @@ "4 Arab World ARB 1972 4.331606e+10" ] }, - "execution_count": 4, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } @@ -300,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 80, "metadata": { "scrolled": true }, @@ -369,7 +371,7 @@ "4 7/4/17 0:00 -" ] }, - "execution_count": 5, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -402,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 84, "metadata": {}, "outputs": [], "source": [ @@ -412,7 +414,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 86, "metadata": {}, "outputs": [ { @@ -479,7 +481,7 @@ "4 6/4/17 0:00 -" ] }, - "execution_count": 7, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } @@ -501,7 +503,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 89, "metadata": {}, "outputs": [], "source": [ @@ -512,7 +514,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 91, "metadata": {}, "outputs": [ { @@ -579,7 +581,7 @@ "4 6/4/17 0:00 NaN" ] }, - "execution_count": 9, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -601,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 94, "metadata": {}, "outputs": [], "source": [ @@ -613,7 +615,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 96, "metadata": { "scrolled": true }, @@ -682,7 +684,7 @@ "4 6/4/17 0:00 NaN" ] }, - "execution_count": 11, + "execution_count": 96, "metadata": {}, "output_type": "execute_result" } @@ -707,7 +709,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 99, "metadata": {}, "outputs": [], "source": [ @@ -720,7 +722,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 101, "metadata": {}, "outputs": [ { @@ -787,7 +789,7 @@ "4 6/4/17 0:00 NaN" ] }, - "execution_count": 13, + "execution_count": 101, "metadata": {}, "output_type": "execute_result" } @@ -798,7 +800,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 103, "metadata": {}, "outputs": [ { @@ -809,7 +811,7 @@ "dtype: object" ] }, - "execution_count": 14, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } @@ -829,7 +831,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 132, "metadata": {}, "outputs": [ { @@ -843,27 +845,27 @@ "Name: Timestamp, dtype: datetime64[ns]" ] }, - "execution_count": 15, + "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "pd.to_datetime(df['Timestamp']).head()" + "pd.to_datetime(df['Timestamp'], format='%d/%m/%Y').head()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 141, "metadata": {}, "outputs": [], "source": [ - "df['Timestamp'] = pd.to_datetime(df['Timestamp'])" + "df['Timestamp'] = pd.to_datetime(df['Timestamp'], format='%d/%m/%Y')" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 143, "metadata": {}, "outputs": [ { @@ -930,7 +932,7 @@ "4 2017-06-04 NaN" ] }, - "execution_count": 17, + "execution_count": 143, "metadata": {}, "output_type": "execute_result" } @@ -941,7 +943,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 145, "metadata": {}, "outputs": [ { @@ -952,7 +954,7 @@ "dtype: object" ] }, - "execution_count": 18, + "execution_count": 145, "metadata": {}, "output_type": "execute_result" } @@ -974,23 +976,24 @@ }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "scrolled": false - }, + "execution_count": 166, + "metadata": {}, "outputs": [], "source": [ + "date_parser = lambda x: pd.to_datetime(x, format='%d/%m/%Y')\n", "df = pd.read_csv('btc-market-price.csv',\n", " header=None,\n", " na_values=['', '?', '-'],\n", " names=['Timestamp', 'Price'],\n", " dtype={'Price': 'float'},\n", - " parse_dates=[0])" + " parse_dates=[0],\n", + " date_format = date_parser\n", + ")" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 168, "metadata": {}, "outputs": [ { @@ -1021,27 +1024,27 @@ " \n", " \n", " 0\n", - " 2017-02-04\n", + " 2/4/17 0:00\n", " 1099.169125\n", " \n", " \n", " 1\n", - " 2017-03-04\n", + " 3/4/17 0:00\n", " 1141.813000\n", " \n", " \n", " 2\n", - " 2017-04-04\n", + " 4/4/17 0:00\n", " NaN\n", " \n", " \n", " 3\n", - " 2017-05-04\n", + " 5/4/17 0:00\n", " 1133.079314\n", " \n", " \n", " 4\n", - " 2017-06-04\n", + " 6/4/17 0:00\n", " NaN\n", " \n", " \n", @@ -1049,15 +1052,15 @@ "" ], "text/plain": [ - " Timestamp Price\n", - "0 2017-02-04 1099.169125\n", - "1 2017-03-04 1141.813000\n", - "2 2017-04-04 NaN\n", - "3 2017-05-04 1133.079314\n", - "4 2017-06-04 NaN" + " Timestamp Price\n", + "0 2/4/17 0:00 1099.169125\n", + "1 3/4/17 0:00 1141.813000\n", + "2 4/4/17 0:00 NaN\n", + "3 5/4/17 0:00 1133.079314\n", + "4 6/4/17 0:00 NaN" ] }, - "execution_count": 20, + "execution_count": 168, "metadata": {}, "output_type": "execute_result" } @@ -1068,18 +1071,18 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 170, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Timestamp datetime64[ns]\n", - "Price float64\n", + "Timestamp object\n", + "Price float64\n", "dtype: object" ] }, - "execution_count": 21, + "execution_count": 170, "metadata": {}, "output_type": "execute_result" } @@ -1103,22 +1106,24 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 181, "metadata": {}, "outputs": [], "source": [ + "date_parser = lambda x: pd.to_datetime(x, '%Y-%m-%d')\n", "df = pd.read_csv('btc-market-price.csv',\n", " header=None,\n", " na_values=['', '?', '-'],\n", " names=['Timestamp', 'Price'],\n", " dtype={'Price': 'float'},\n", " parse_dates=[0],\n", - " index_col=[0])" + " index_col=[0],\n", + " date_format = date_parser)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 183, "metadata": {}, "outputs": [ { @@ -1151,23 +1156,23 @@ " \n", " \n", " \n", - " 2017-02-04\n", + " 2/4/17 0:00\n", " 1099.169125\n", " \n", " \n", - " 2017-03-04\n", + " 3/4/17 0:00\n", " 1141.813000\n", " \n", " \n", - " 2017-04-04\n", + " 4/4/17 0:00\n", " NaN\n", " \n", " \n", - " 2017-05-04\n", + " 5/4/17 0:00\n", " 1133.079314\n", " \n", " \n", - " 2017-06-04\n", + " 6/4/17 0:00\n", " NaN\n", " \n", " \n", @@ -1175,16 +1180,16 @@ "" ], "text/plain": [ - " Price\n", - "Timestamp \n", - "2017-02-04 1099.169125\n", - "2017-03-04 1141.813000\n", - "2017-04-04 NaN\n", - "2017-05-04 1133.079314\n", - "2017-06-04 NaN" + " Price\n", + "Timestamp \n", + "2/4/17 0:00 1099.169125\n", + "3/4/17 0:00 1141.813000\n", + "4/4/17 0:00 NaN\n", + "5/4/17 0:00 1133.079314\n", + "6/4/17 0:00 NaN" ] }, - "execution_count": 5, + "execution_count": 183, "metadata": {}, "output_type": "execute_result" } @@ -1195,7 +1200,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 185, "metadata": {}, "outputs": [ { @@ -1205,7 +1210,7 @@ "dtype: object" ] }, - "execution_count": 24, + "execution_count": 185, "metadata": {}, "output_type": "execute_result" } @@ -1236,7 +1241,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 188, "metadata": {}, "outputs": [], "source": [ @@ -1245,7 +1250,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 190, "metadata": { "scrolled": true }, @@ -1314,7 +1319,7 @@ "Amy>Grimes>23>91>81 NaN NaN" ] }, - "execution_count": 7, + "execution_count": 190, "metadata": {}, "output_type": "execute_result" } @@ -1340,7 +1345,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 193, "metadata": {}, "outputs": [], "source": [ @@ -1350,7 +1355,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 195, "metadata": { "scrolled": true }, @@ -1437,7 +1442,7 @@ "4 Amy Grimes 23 91 81" ] }, - "execution_count": 9, + "execution_count": 195, "metadata": {}, "output_type": "execute_result" } @@ -1477,7 +1482,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 199, "metadata": {}, "outputs": [], "source": [ @@ -1487,7 +1492,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 201, "metadata": {}, "outputs": [ { @@ -1572,7 +1577,7 @@ "4 Amy Grimes 23 91 81" ] }, - "execution_count": 13, + "execution_count": 201, "metadata": {}, "output_type": "execute_result" } @@ -1583,7 +1588,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 203, "metadata": {}, "outputs": [ { @@ -1594,7 +1599,7 @@ "dtype: object" ] }, - "execution_count": 14, + "execution_count": 203, "metadata": {}, "output_type": "execute_result" } @@ -1612,7 +1617,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 206, "metadata": {}, "outputs": [], "source": [ @@ -1623,7 +1628,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 208, "metadata": {}, "outputs": [ { @@ -1708,7 +1713,7 @@ "4 Amy Grimes 23 91.0 81.0" ] }, - "execution_count": 16, + "execution_count": 208, "metadata": {}, "output_type": "execute_result" } @@ -1719,7 +1724,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 210, "metadata": {}, "outputs": [ { @@ -1730,7 +1735,7 @@ "dtype: object" ] }, - "execution_count": 34, + "execution_count": 210, "metadata": {}, "output_type": "execute_result" } @@ -1748,7 +1753,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 213, "metadata": {}, "outputs": [ { @@ -1833,7 +1838,7 @@ "4 Amy Grimes 23 91 81" ] }, - "execution_count": 35, + "execution_count": 213, "metadata": {}, "output_type": "execute_result" } @@ -1860,7 +1865,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 216, "metadata": {}, "outputs": [], "source": [ @@ -1871,7 +1876,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 218, "metadata": {}, "outputs": [ { @@ -1956,7 +1961,7 @@ "4 Amy Grimes 23 91.0 81.0" ] }, - "execution_count": 18, + "execution_count": 218, "metadata": {}, "output_type": "execute_result" } @@ -1974,7 +1979,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 221, "metadata": {}, "outputs": [ { @@ -2041,7 +2046,7 @@ "2 Amy Grimes 23 91 81" ] }, - "execution_count": 19, + "execution_count": 221, "metadata": {}, "output_type": "execute_result" } @@ -2061,7 +2066,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 224, "metadata": {}, "outputs": [], "source": [ @@ -2073,7 +2078,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 226, "metadata": {}, "outputs": [ { @@ -2140,7 +2145,7 @@ "2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 21, + "execution_count": 226, "metadata": {}, "output_type": "execute_result" } @@ -2164,7 +2169,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 229, "metadata": {}, "outputs": [ { @@ -2258,7 +2263,7 @@ "5 Amy Grimes 23.0 91 81" ] }, - "execution_count": 22, + "execution_count": 229, "metadata": {}, "output_type": "execute_result" } @@ -2286,7 +2291,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 232, "metadata": {}, "outputs": [ { @@ -2359,7 +2364,7 @@ "4 Amy Grimes 23" ] }, - "execution_count": 42, + "execution_count": 232, "metadata": {}, "output_type": "execute_result" } @@ -2379,7 +2384,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 235, "metadata": {}, "outputs": [ { @@ -2452,7 +2457,7 @@ "4 Amy Grimes 23" ] }, - "execution_count": 43, + "execution_count": 235, "metadata": {}, "output_type": "execute_result" } @@ -2476,7 +2481,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 238, "metadata": {}, "outputs": [], "source": [ @@ -2487,7 +2492,79 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 272, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
last_name
0Morley
1Scott
2Haley
3Mills
4Grimes
\n", + "
" + ], + "text/plain": [ + " last_name\n", + "0 Morley\n", + "1 Scott\n", + "2 Haley\n", + "3 Mills\n", + "4 Grimes" + ] + }, + "execution_count": 272, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exam_test_1" + ] + }, + { + "cell_type": "code", + "execution_count": 325, "metadata": {}, "outputs": [ { @@ -2496,7 +2573,7 @@ "pandas.core.frame.DataFrame" ] }, - "execution_count": 45, + "execution_count": 325, "metadata": {}, "output_type": "execute_result" } @@ -2507,19 +2584,43 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 337, "metadata": {}, "outputs": [], "source": [ "exam_test_2 = pd.read_csv('exam_review.csv',\n", " sep='>',\n", - " usecols=['last_name'],\n", - " squeeze=True)" + " usecols=['last_name']).squeeze()" + ] + }, + { + "cell_type": "code", + "execution_count": 339, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 Morley\n", + "1 Scott\n", + "2 Haley\n", + "3 Mills\n", + "4 Grimes\n", + "Name: last_name, dtype: object" + ] + }, + "execution_count": 339, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exam_test_2" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 341, "metadata": {}, "outputs": [ { @@ -2528,7 +2629,7 @@ "pandas.core.series.Series" ] }, - "execution_count": 47, + "execution_count": 341, "metadata": {}, "output_type": "execute_result" } @@ -2550,7 +2651,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 344, "metadata": {}, "outputs": [ { @@ -2617,7 +2718,7 @@ "2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 48, + "execution_count": 344, "metadata": {}, "output_type": "execute_result" } @@ -2635,16 +2736,16 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 347, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "',first_name,last_name,age,math_score,french_score\\n0,Melvin,Scott,24,77.0,83\\n1,Gerard,Mills,19,78.0,72\\n2,Amy,Grimes,23,91.0,81\\n'" + "',first_name,last_name,age,math_score,french_score\\r\\n0,Melvin,Scott,24,77.0,83\\r\\n1,Gerard,Mills,19,78.0,72\\r\\n2,Amy,Grimes,23,91.0,81\\r\\n'" ] }, - "execution_count": 49, + "execution_count": 347, "metadata": {}, "output_type": "execute_result" } @@ -2662,7 +2763,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 350, "metadata": {}, "outputs": [], "source": [ @@ -2671,7 +2772,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 352, "metadata": {}, "outputs": [ { @@ -2742,7 +2843,7 @@ "2 2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 51, + "execution_count": 352, "metadata": {}, "output_type": "execute_result" } @@ -2753,7 +2854,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 354, "metadata": {}, "outputs": [], "source": [ @@ -2763,7 +2864,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 356, "metadata": { "scrolled": true }, @@ -2832,7 +2933,7 @@ "2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 53, + "execution_count": 356, "metadata": {}, "output_type": "execute_result" } @@ -2851,7 +2952,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -2865,9 +2966,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.12.4" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/out.csv b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/out.csv new file mode 100644 index 0000000..44a666c --- /dev/null +++ b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/out.csv @@ -0,0 +1,4 @@ +first_name,last_name,age,math_score,french_score +Melvin,Scott,24,77.0,83 +Gerard,Mills,19,78.0,72 +Amy,Grimes,23,91.0,81 From c3babce62aaee1846c3044cf27a40becc152ca00 Mon Sep 17 00:00:00 2001 From: "floydnbrooks@gmail.comgit config --global user.email" Date: Tue, 9 Jul 2024 14:22:57 -0400 Subject: [PATCH 2/2] added .squeeze() method as the squeeze = bool has been deprecated. Also, the time format in respected areas was modified to add the date format. --- .../files/Lecture.ipynb | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb index b8de3f7..28a7870 100644 --- a/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb +++ b/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files/Lecture.ipynb @@ -2,9 +2,7 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ "![rmotr](https://user-images.githubusercontent.com/7065401/52071918-bda15380-2562-11e9-828c-7f95297e4a82.png)\n", "
\n", @@ -2476,12 +2474,12 @@ "\n", "## Using a `Series` instead of `DataFrame`\n", "\n", - "If the parsed data only contains one column then we can return a Series by setting the `squeeze` parameter to `True`." + "The approach of returning a Series when the parsed data contains only one column has transitioned from using the squeeze=True parameter to utilizing the .squeeze() method." ] }, { "cell_type": "code", - "execution_count": 238, + "execution_count": 383, "metadata": {}, "outputs": [], "source": [ @@ -2492,7 +2490,7 @@ }, { "cell_type": "code", - "execution_count": 272, + "execution_count": 385, "metadata": {}, "outputs": [ { @@ -2553,7 +2551,7 @@ "4 Grimes" ] }, - "execution_count": 272, + "execution_count": 385, "metadata": {}, "output_type": "execute_result" } @@ -2564,7 +2562,7 @@ }, { "cell_type": "code", - "execution_count": 325, + "execution_count": 387, "metadata": {}, "outputs": [ { @@ -2573,7 +2571,7 @@ "pandas.core.frame.DataFrame" ] }, - "execution_count": 325, + "execution_count": 387, "metadata": {}, "output_type": "execute_result" } @@ -2582,20 +2580,28 @@ "type(exam_test_1)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Squeeze the CSV Data\n", + "https://pandas.pydata.org/pandas-docs/version/1.5.0/reference/api/pandas.read_csv.html\n" + ] + }, { "cell_type": "code", - "execution_count": 337, + "execution_count": 390, "metadata": {}, "outputs": [], "source": [ "exam_test_2 = pd.read_csv('exam_review.csv',\n", " sep='>',\n", - " usecols=['last_name']).squeeze()" + " usecols=['last_name']).squeeze() # the squeeze method converts the column to a series after reading the CSV file" ] }, { "cell_type": "code", - "execution_count": 339, + "execution_count": 392, "metadata": {}, "outputs": [ { @@ -2609,7 +2615,7 @@ "Name: last_name, dtype: object" ] }, - "execution_count": 339, + "execution_count": 392, "metadata": {}, "output_type": "execute_result" } @@ -2620,7 +2626,7 @@ }, { "cell_type": "code", - "execution_count": 341, + "execution_count": 394, "metadata": {}, "outputs": [ { @@ -2629,7 +2635,7 @@ "pandas.core.series.Series" ] }, - "execution_count": 341, + "execution_count": 394, "metadata": {}, "output_type": "execute_result" } @@ -2651,7 +2657,7 @@ }, { "cell_type": "code", - "execution_count": 344, + "execution_count": 397, "metadata": {}, "outputs": [ { @@ -2718,7 +2724,7 @@ "2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 344, + "execution_count": 397, "metadata": {}, "output_type": "execute_result" } @@ -2736,7 +2742,7 @@ }, { "cell_type": "code", - "execution_count": 347, + "execution_count": 400, "metadata": {}, "outputs": [ { @@ -2745,7 +2751,7 @@ "',first_name,last_name,age,math_score,french_score\\r\\n0,Melvin,Scott,24,77.0,83\\r\\n1,Gerard,Mills,19,78.0,72\\r\\n2,Amy,Grimes,23,91.0,81\\r\\n'" ] }, - "execution_count": 347, + "execution_count": 400, "metadata": {}, "output_type": "execute_result" } @@ -2763,7 +2769,7 @@ }, { "cell_type": "code", - "execution_count": 350, + "execution_count": 403, "metadata": {}, "outputs": [], "source": [ @@ -2772,7 +2778,7 @@ }, { "cell_type": "code", - "execution_count": 352, + "execution_count": 405, "metadata": {}, "outputs": [ { @@ -2843,7 +2849,7 @@ "2 2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 352, + "execution_count": 405, "metadata": {}, "output_type": "execute_result" } @@ -2854,7 +2860,7 @@ }, { "cell_type": "code", - "execution_count": 354, + "execution_count": 407, "metadata": {}, "outputs": [], "source": [ @@ -2864,7 +2870,7 @@ }, { "cell_type": "code", - "execution_count": 356, + "execution_count": 409, "metadata": { "scrolled": true }, @@ -2933,7 +2939,7 @@ "2 Amy Grimes 23 91.0 81" ] }, - "execution_count": 356, + "execution_count": 409, "metadata": {}, "output_type": "execute_result" }