Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index.
Dictionaries | Panda's Series |
---|---|
Allows you to store key: value pairs and offer some built-in methods to manipulate your data | These are one-dimensional ndarrays with axis-labels, which allow you to store array-like, dict, or scalar values |
If you only need to store some key:value pairs, your best and more elegant solution is to use the default dictionary | If you need to make some complex data manipulation on the stored data, then consider using panda's series |
Create Series object from list and dictionaries
import pandas as pd
# Create series of students with their ids using lists
se = pd.Series(data=['Alex', 'Nelly', 'Mike'], index=[100, 101, 102])
print(se)
# Create a series from students dict
se = pd.Series(data={100: 'Alex', 101: 'Nelly', 102: 'Mike'})
print(se)
Indexes can be used to retrieve elements in series
Series[startIndex:endIndex]. Note endIndex element is not retrieved
# Slicing
# Retrieve all elements
se[:]
>>>
100 Alex
101 Nelly
102 Mike
dtype: object
# Retrieve first element
se[0:1]
>>>
100 Alex
dtype: object
series[index]=newelement
del series[index]
del series