Values can be set and accessed using the index label in a dictionary-like manner:
# Accessing value from series using index label
In [26]: currDict['China']
Out[26]: 'yuan'
# Assigning value to series through a new index label
In [27]: stockPriceSeries['GOOG'] = 1200.0
In [28]: stockPriceSeries
Out[28]:
GOOG 1200.00
FB 62.57
YHOO NaN
TWTR 64.50
AMZN 358.69
AAPL 500.60
Name: stockPrices, dtype: float64
Just as in the case of dict, KeyError is raised if you try to retrieve a missing label:
In [29]: stockPriceSeries['MSFT']
KeyError: 'MSFT'
This error can be avoided by explicitly using get as follows:
In [30]: stockPriceSeries.get('MSFT, np.NaN)
Out[30]: nan
In this case, the default value of np.NaN is specified as the value to return when the key does not exist in the Series structure.