Basic selection from a Series
Selection from a pd.Series
involves accessing elements either by their position or by their label. This is akin to accessing elements in a list by their index or in a dictionary by their key, respectively. The versatility of the pd.Series
object allows intuitive and straightforward data retrieval, making it an essential tool for data manipulation.
The pd.Series
is considered a container in Python, much like the built-in list
, tuple
, and dict
objects. As such, for simple selection operations, the first place users turn to is the Python index operator, using the []
syntax.
How to do it
To introduce the basics of selection, let’s start with a very simple pd.Series
:
ser = pd.Series(list("abc") * 3)
ser
0 a
1 b
2 c
3 a
4 b
5 c
6 a
7 b
8 c
dtype: object
In Python, you’ve already discovered that the []
operator can be used to select elements from a container; i.e., some_dictionary[0...