ENH: Add na_value to DataFrame.to_numpy · Issue #33820 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@TomAugspurger

Description

@TomAugspurger

Control the NA value used when converting a DataFrame to an ndarray.

Describe the solution you'd like

Add an na_value argument to DataFrame.to_numpy(). Has the same meaning as na_value in Series.to_numpy, except it applies to all the columns.

Additional context

In [8]: df = pd.DataFrame({"A": pd.array([1, None])})

In [9]: df.to_numpy(na_value=np.nan)

This has come up in a few places (cc @jorisvandenbossche @dsaxton)