4.2 Datetimes

For datetime64[ns] types, NaT represents missing values. This is a pseudo-native sentinel value that can be represented by numpy in a singular dtype (datetime64[ns]). pandas objects provide intercompatibility between NaT and NaN.

In [1]: df2 = df.copy()

In [2]: df2
Out[2]: 
      one     two   three four  five
a  1.7641  0.4002  0.9787  bar  True
c  2.2409  1.8676 -0.9773  bar  True
e  0.9501 -0.1514 -0.1032  bar  True
f  0.4106  0.1440  1.4543  bar  True
h  0.7610  0.1217  0.4439  bar  True

In [3]: df2['timestamp'] = pd.Timestamp('20120101')

In [4]: df2
Out[4]: 
      one     two   three four  five  timestamp
a  1.7641  0.4002  0.9787  bar  True 2012-01-01
c  2.2409  1.8676 -0.9773  bar  True 2012-01-01
e  0.9501 -0.1514 -0.1032  bar  True 2012-01-01
f  0.4106  0.1440  1.4543  bar  True 2012-01-01
h  0.7610  0.1217  0.4439  bar  True 2012-01-01

In [5]: df2.ix[['a','c','h'],['one','timestamp']] = np.nan

In [6]: df2
Out[6]: 
      one     two   three four  five  timestamp
a     NaN  0.4002  0.9787  bar  True        NaT
c     NaN  1.8676 -0.9773  bar  True        NaT
e  0.9501 -0.1514 -0.1032  bar  True 2012-01-01
f  0.4106  0.1440  1.4543  bar  True 2012-01-01
h     NaN  0.1217  0.4439  bar  True        NaT

In [7]: df2.get_dtype_counts()
Out[7]: 
bool              1
datetime64[ns]    1
float64           3
object            1
dtype: int64