Introduction To Pandas Indexes and Operations
In the previous blog post, we went over the two main panda’s data structures: Series and Dataframe. In this blog post, we are going to take things a step further and introduce you to Panda’s indexes and the operations you can perform on them.
First, let’s initial a series with a character-based index (which we used in the previous blog post)
In [6]: s3 = Series([1,2,3,4],index=['a','b','c','d'])
One very useful feature is that indexes can be used the same way list index/numpy array indexes, except with non-integer values:
In [7]: s3
Out[7]:
a 1
b 2
c 3
d 4
dtype: int64
In [8]: s3[['a']]
Out[8]:
a 1
dtype: int64
In [9]: s3[['a','b']]
Out[9]:
a 1
b 2
dtype: int64
They also support list/array like slicing, but again, on non-integer values:
In [11]: s3['a':'b']
Out[11]:
a 1
b 2
dtype: int64