October 2019
Beginner to intermediate
674 pages
16h 43m
English
Values can be set and accessed using the index label in a dictionary-like manner:
# Accessing value from series using index labelIn [26]: currDict['China']Out[26]: 'yuan'# Assigning value to series through a new index labelIn [27]: stockPriceSeries['GOOG'] = 1200.0In [28]: stockPriceSeriesOut[28]:GOOG 1200.00FB 62.57YHOO NaNTWTR 64.50AMZN 358.69AAPL 500.60Name: 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 ...
Read now
Unlock full access