Skip to content
Advertisement

Convert np.nan to pd.NA

How can I convert np.nan into the new pd.NA format, given the pd.DataFrame comprises float?

JavaScript

Making use of pd.convert_dtypes() doesn’t seem to work when df comprises float. This conversion is however working fine when df contains int.

Advertisement

Answer

From v1.2 this now works with floats by default and if you want integer use convert_floating=False parameter.

JavaScript

output

JavaScript

Working with ints

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement