4b Understanding Series in Pandas - PPTX - Lyst2672
4b Understanding Series in Pandas - PPTX - Lyst2672
• ndArray
• Dict
• Scalar value or constant
Create a Series from ndarray
data = np.array(['a','b','c','d'])
s = pd.Series(data)
print s
Lets pass the index values here. Now we can see the
customized indexed values in the output.
s = pd.Series(data,index=[100,101,102,103])
print s
Create a Series from dict
• A dictionery can be passed as input and if no index is
specified, then the dictionary keys are taken in a
sorted order to construct index. If index is passed, the
values in data corresponding to the labels in the index
will be pulled out.
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
#retrieve the first element
print s[0]
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
#retrieve multiple elements
print s[['a','c','d']]