You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/03-index-slice-subset.md
+23-17Lines changed: 23 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,25 +12,27 @@ objectives:
12
12
- "Employ label and integer-based indexing to select ranges of data in a dataframe."
13
13
- "Reassign values within subsets of a DataFrame."
14
14
- "Create a copy of a DataFrame."
15
-
- "Query /select a subset of data using a set of criteria using the following operators: =, !=, >, <, >=, <=."
15
+
- "Query / select a subset of data using a set of criteria using the following operators:
16
+
`=`, `!=`, `>`, `<`, `>=`, `<=`."
16
17
- "Locate subsets of data using masks."
17
18
- "Describe BOOLEAN objects in Python and manipulate data using BOOLEANs."
18
19
keypoints:
19
-
- "In Python, portions of data can be accessed using indices, slices, column headings, and condition-based subsetting."
20
-
- "Python uses 0-based indexing, in which the first element in a list, tuple or any other data structure has an index of 0."
21
-
- "Pandas enables common data exploration steps such as data indexing, slicing and conditional subsetting."
22
-
20
+
- "In Python, portions of data can be accessed using indices, slices, column headings, and
21
+
condition-based subsetting."
22
+
- "Python uses 0-based indexing, in which the first element in a list, tuple or any other data
23
+
structure has an index of 0."
24
+
- "Pandas enables common data exploration steps such as data indexing, slicing and conditional
25
+
subsetting."
23
26
---
24
27
25
-
In lesson 01, we read a CSV into a Python pandas DataFrame. We learned:
28
+
In the first episode of this lesson, we read a CSV file into a pandas' DataFrame. We learned how to:
26
29
27
-
-how to save the DataFrame to a named object,
28
-
-how to perform basic math on the data,
29
-
-how to calculate summary statistics, and
30
-
-how to create plots of the data.
30
+
- save a DataFrame to a named object,
31
+
- perform basic math on data,
32
+
- calculate summary statistics, and
33
+
- create plots based on the data we loaded into pandas.
31
34
32
-
In this lesson, we will explore **ways to access different parts of the data**
33
-
using:
35
+
In this lesson, we will explore ways to access different parts of the data using:
34
36
35
37
- indexing,
36
38
- slicing, and
@@ -39,7 +41,7 @@ using:
39
41
## Loading our data
40
42
41
43
We will continue to use the surveys dataset that we worked with in the last
42
-
lesson. Let's reopen and read in the data again:
44
+
episode. Let's reopen and read in the data again:
43
45
44
46
~~~
45
47
# Make sure pandas is loaded
@@ -100,11 +102,15 @@ surveys_df['speciess']
100
102
~~~
101
103
{: .language-python}
102
104
103
-
Python tells us what type of error it is in the traceback, at the bottom it says `KeyError: 'speciess'` which means that `speciess` is not a column name (or Key in the related Python data type dictionary).
105
+
Python tells us what type of error it is in the traceback, at the bottom it says
106
+
`KeyError: 'speciess'` which means that `speciess` is not a valid column name (nor a valid key in
107
+
the related Python data type dictionary).
104
108
105
109
## Extracting Range based Subsets: Slicing
106
110
107
-
**REMINDER**: Python Uses 0-based Indexing
111
+
> ## Reminder
112
+
> Python uses 0-based indexing.
113
+
{: .callout}
108
114
109
115
Let's remind ourselves that Python uses 0-based
110
116
indexing. This means that the first element in an object is located at position
@@ -458,8 +464,8 @@ x == 5
458
464
~~~
459
465
{: .language-python}
460
466
461
-
When we ask Python whether `x` is greater than 5, it returns `False`.
462
-
This is Python's way to say "No". Indeed, the value of `x` is 5,
467
+
When we ask Python whether `x` is greater than 5, it returns `False`.
468
+
This is Python's way to say "No". Indeed, the value of `x` is 5,
0 commit comments