Slicing & Indexing
Learn how to select subsets of data on Autogon using slice notation. This concise syntax allows you to select elements based on various criteria, including specific indices, labels, and ranges.
Slicing Notation
Our slice notation is a way of selecting subsets of a specified dataset using a concise, Pythonic syntax. This notation can be used to select rows and columns based on various criteria.
Selecting Rows
To select rows using slice notation, you can use the following syntax:
Here, start
and end
are the starting and ending indices of the slice, respectively. Note that the slice is inclusive of the starting index and exclusive of the ending index.
For example, to select rows 1 to 3 of a dataset, you can use the following slice:
This selects rows 1, 2, and 3 (because the slice is inclusive of the starting index 1 and exclusive of the ending index 4).
You can also use negative indices to select rows from the end of the data. For example, to select the last 3 rows, you can use the following slice:
This selects the last 3 rows of the dataset (because the slice starts at index -3 and continues to the end of the dataset).
Selecting Columns
To select columns using slice notation, you can use the following syntax:
Here, start
and end
are the starting and ending column labels of the slice, respectively. Note that the slice is inclusive of the starting label and exclusive of the ending label.
For example, to select columns "A" through "C" of your dataset, you can use the following slice:
This selects columns "A", "B", and "C" (because the slice is inclusive of the starting label "A" and exclusive of the ending label "D").
You can also use negative indices to select columns from the end of the dataset. For example, to select all columns except for the last column of a dataset, you can use the following slice:
This selects all columns up to, but not including, the last column of the dataset.
Selecting Rows and Columns
To select both rows and columns using slice notation, you can combine the row and column slices using the following syntax:
For example, to select rows 1 to 3 and columns "A" through "C" of your dataset, you can use the following slice:
This selects rows 1, 2, and 3 and columns "A", "B", and "C" (because the slices are inclusive of the starting indices and exclusive of the ending indices).
Last updated