.. ipython:: python :suppress: import numpy as np import pandas as pd np.random.seed(10) pd.options.display.max_rows=15 import matplotlib matplotlib.style.use('ggplot') import matplotlib.pyplot as plt Missing data casting rules and indexing --------------------------------------- While pandas supports storing arrays of integer and boolean type, these types are not capable of storing missing data. Until we can switch to using a native NA type in NumPy, we've established some "casting rules" when reindexing will cause missing data to be introduced into, say, a Series or DataFrame. Here they are: .. csv-table:: :header: "data type", "Cast to" :widths: 40, 40 integer, float boolean, object float, no cast object, no cast For example: .. ipython:: python s = pd.Series(np.random.randn(5), index=[0, 2, 4, 6, 7]) s s > 0 (s > 0).dtype crit = (s > 0).reindex(list(range(8))) crit crit.dtype Ordinarily NumPy will complain if you try to use an object array (even if it contains boolean values) instead of a boolean array to get or set values from an ndarray (e.g. selecting values based on some criteria). If a boolean vector contains NAs, an exception will be generated: .. ipython:: python :okexcept: reindexed = s.reindex(list(range(8))).fillna(0) reindexed[crit] However, these can be filled in using **fillna** and it will work fine: .. ipython:: python reindexed[crit.fillna(False)] reindexed[crit.fillna(True)]