pandas 1.4.2

ParametersReturnsBackRef
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.

Parameters

dtype : str or numpy.dtype, optional

The dtype to pass to numpy.asarray .

copy : bool, default False

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.

na_value : Any, optional

The value to use for missing values. The default value depends on dtype and the dtypes of the DataFrame columns.

versionadded

Returns

numpy.ndarray

Convert the DataFrame to a NumPy array.

See Also

Series.to_numpy

Similar method for Series.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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)
... 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)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.base.IndexOpsMixin.to_numpy

Local connectivity graph

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


File: /pandas/core/frame.py#1693
type: <class 'function'>
Commit: