@@ -64,37 +64,37 @@ NumPy's type system to add support for custom arrays
64
64
(see :ref: `basics.dtypes `).
65
65
66
66
To get the actual data inside a :class: `Index ` or :class: `Series `, use
67
- the ** array ** property
67
+ the `` . array`` property
68
68
69
69
.. ipython :: python
70
70
71
71
s.array
72
72
s.index.array
73
73
74
74
:attr: `~Series.array ` will always be an :class: `~pandas.api.extensions.ExtensionArray `.
75
- The exact details of what an `` ExtensionArray ` ` is and why pandas uses them is a bit
75
+ The exact details of what an :class: ` ~pandas.api.extensions. ExtensionArray ` is and why pandas uses them is a bit
76
76
beyond the scope of this introduction. See :ref: `basics.dtypes ` for more.
77
77
78
78
If you know you need a NumPy array, use :meth: `~Series.to_numpy `
79
- or :meth: `numpy.asarray `.
79
+ or :meth: `numpy.ndarray. asarray `.
80
80
81
81
.. ipython :: python
82
82
83
83
s.to_numpy()
84
84
np.asarray(s)
85
85
86
86
When the Series or Index is backed by
87
- an :class: `~pandas.api.extension .ExtensionArray `, :meth: `~Series.to_numpy `
87
+ an :class: `~pandas.api.extensions .ExtensionArray `, :meth: `~Series.to_numpy `
88
88
may involve copying data and coercing values. See :ref: `basics.dtypes ` for more.
89
89
90
90
:meth: `~Series.to_numpy ` gives some control over the ``dtype `` of the
91
- resulting :class: `ndarray `. For example, consider datetimes with timezones.
91
+ resulting :class: `numpy. ndarray `. For example, consider datetimes with timezones.
92
92
NumPy doesn't have a dtype to represent timezone-aware datetimes, so there
93
93
are two possibly useful representations:
94
94
95
- 1. An object-dtype :class: `ndarray ` with :class: `Timestamp ` objects, each
95
+ 1. An object-dtype :class: `numpy. ndarray ` with :class: `Timestamp ` objects, each
96
96
with the correct ``tz ``
97
- 2. A ``datetime64[ns] `` -dtype :class: `ndarray `, where the values have
97
+ 2. A ``datetime64[ns] `` -dtype :class: `numpy. ndarray `, where the values have
98
98
been converted to UTC and the timezone discarded
99
99
100
100
Timezones may be preserved with ``dtype=object ``
@@ -106,6 +106,8 @@ Timezones may be preserved with ``dtype=object``
106
106
107
107
Or thrown away with ``dtype='datetime64[ns]' ``
108
108
109
+ .. ipython :: python
110
+
109
111
ser.to_numpy(dtype = " datetime64[ns]" )
110
112
111
113
Getting the "raw data" inside a :class: `DataFrame ` is possibly a bit more
@@ -137,7 +139,7 @@ drawbacks:
137
139
138
140
1. When your Series contains an :ref: `extension type <extending.extension-types >`, it's
139
141
unclear whether :attr: `Series.values ` returns a NumPy array or the extension array.
140
- :attr: `Series.array ` will always return an `` ExtensionArray ` `, and will never
142
+ :attr: `Series.array ` will always return an :class: ` ~pandas.api.extensions. ExtensionArray `, and will never
141
143
copy data. :meth: `Series.to_numpy ` will always return a NumPy array,
142
144
potentially at the cost of copying / coercing values.
143
145
2. When your DataFrame contains a mixture of data types, :attr: `DataFrame.values ` may
0 commit comments