插入缺失的数据

You can insert missing values by simply assigning to containers. The actual missing value used will be chosen based on the dtype.

For example, numeric containers will always use NaN regardless of the missing value type chosen:

  1. In [20]: s = pd.Series([1, 2, 3])
  2. In [21]: s.loc[0] = None
  3. In [22]: s
  4. Out[22]:
  5. 0 NaN
  6. 1 2.0
  7. 2 3.0
  8. dtype: float64

Likewise, datetime containers will always use NaT.

For object containers, pandas will use the value given:

  1. In [23]: s = pd.Series(["a", "b", "c"])
  2. In [24]: s.loc[0] = None
  3. In [25]: s.loc[1] = np.nan
  4. In [26]: s
  5. Out[26]:
  6. 0 None
  7. 1 NaN
  8. 2 c
  9. dtype: object