日期时间

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.

  1. In [14]: df2 = df.copy()
  2. In [15]: df2['timestamp'] = pd.Timestamp('20120101')
  3. In [16]: df2
  4. Out[16]:
  5. one two three four five timestamp
  6. a -0.166778 0.501113 -0.355322 bar False 2012-01-01
  7. c -0.337890 0.580967 0.983801 bar False 2012-01-01
  8. e 0.057802 0.761948 -0.712964 bar True 2012-01-01
  9. f -0.443160 -0.974602 1.047704 bar False 2012-01-01
  10. h -0.717852 -1.053898 -0.019369 bar False 2012-01-01
  11. In [17]: df2.loc[['a','c','h'],['one','timestamp']] = np.nan
  12. In [18]: df2
  13. Out[18]:
  14. one two three four five timestamp
  15. a NaN 0.501113 -0.355322 bar False NaT
  16. c NaN 0.580967 0.983801 bar False NaT
  17. e 0.057802 0.761948 -0.712964 bar True 2012-01-01
  18. f -0.443160 -0.974602 1.047704 bar False 2012-01-01
  19. h NaN -1.053898 -0.019369 bar False NaT
  20. In [19]: df2.get_dtype_counts()
  21. Out[19]:
  22. float64 3
  23. object 1
  24. bool 1
  25. datetime64[ns] 1
  26. dtype: int64