Examples

In [1]:
import numpy as np
import pandas as pd
In [3]:
s = pd.Series(pd.Categorical(['p', 'q', 'p']))
s.to_numpy()
Out[3]:
array(['p', 'q', 'p'], dtype=object)

Specify the dtype to control how datetime-aware data is represented. Use dtype=object to return an ndarray
of pandas Timestamp objects, each with the correct tz.

In [4]:
s = pd.Series(pd.date_range('2019', periods=4, tz="CET"))
In [5]:
s.to_numpy(dtype=object)
Out[5]:
array([Timestamp('2019-01-01 00:00:00+0100', tz='CET', freq='D'),
       Timestamp('2019-01-02 00:00:00+0100', tz='CET', freq='D'),
       Timestamp('2019-01-03 00:00:00+0100', tz='CET', freq='D'),
       Timestamp('2019-01-04 00:00:00+0100', tz='CET', freq='D')],
      dtype=object)

Or dtype='datetime64[ns]' to return an ndarray of native datetime64 values. The values are converted to UTC and
the timezone info is dropped.

In [6]:
s.to_numpy(dtype="datetime64[ns]")
# doctest: +ELLIPSIS
Out[6]:
array(['2018-12-31T23:00:00.000000000', '2019-01-01T23:00:00.000000000',
       '2019-01-02T23:00:00.000000000', '2019-01-03T23:00:00.000000000'],
      dtype='datetime64[ns]')