Difference between data type 'datetime64[ns]' and '<M8[ns]'?

后端 未结 2 810
温柔的废话
温柔的废话 2020-12-01 01:36

I have created a TimeSeries in pandas:

In [346]: from datetime import datetime

In [347]: dates = [datetime(2011, 1, 2), datetime(2011, 1, 5), datetime(2011,         


        
2条回答
  •  星月不相逢
    2020-12-01 02:33

    datetime64[ns] is a general dtype, while is a specific dtype. General dtypes map to specific dtypes, but may be different from one installation of NumPy to the next.

    On a machine whose byte order is little endian, there is no difference between np.dtype('datetime64[ns]') and np.dtype(':

    In [6]: np.dtype('datetime64[ns]') == np.dtype('

    However, on a big endian machine, np.dtype('datetime64[ns]') would equal np.dtype('>M8[ns]').

    So datetime64[ns] maps to either or >M8[ns] depending on the endian-ness of the machine.

    There are many other similar examples of general dtypes mapping to specific dtypes: int64 maps to or >i8, and int maps to either int32 or int64 depending on the bit architecture of the OS and how NumPy was compiled.


    Apparently, the repr of the datetime64 dtype has change since the time the book was written to show the endian-ness of the dtype.

提交回复
热议问题