to_numpy(self, dtype: 'npt.DTypeLike | None' = None, copy: 'bool' = False, na_value=<no_default>) -> 'np.ndarray'
By default, the dtype of the returned array will be the common NumPy dtype of all types in the DataFrame. For example, if the dtypes are float16
and float32
, the results dtype will be float32
. This may require copying data and coercing values, which may be expensive.
The dtype to pass to numpy.asarray
.
Whether to ensure that the returned value is not a view on another array. Note that copy=False
does not ensure that to_numpy()
is no-copy. Rather, copy=True
ensure that a copy is made, even if not strictly necessary.
The value to use for missing values. The default value depends on dtype
and the dtypes of the DataFrame columns.
Convert the DataFrame to a NumPy array.
Series.to_numpy
Similar method for Series.
>>> pd.DataFrame({"A": [1, 2], "B": [3, 4]}).to_numpy() array([[1, 3], [2, 4]])
With heterogeneous data, the lowest common type will have to be used.
This example is valid syntax, but we were not able to check execution>>> df = pd.DataFrame({"A": [1, 2], "B": [3.0, 4.5]})
... df.to_numpy() array([[1. , 3. ], [2. , 4.5]])
For a mix of numeric and non-numeric types, the output array will have object dtype.
This example is valid syntax, but we were not able to check execution>>> df['C'] = pd.date_range('2000', periods=2)See :
... df.to_numpy() array([[1, 3.0, Timestamp('2000-01-01 00:00:00')], [2, 4.5, Timestamp('2000-01-02 00:00:00')]], dtype=object)
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.base.IndexOpsMixin.to_numpy
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them