Categories
Python Answers

How to keep array type as integer while having a NaN value with Python Pandas?

Spread the love

To keep array type as integer while having a NaN value with Python Pandas, to call dropna to drop toe NaN values.

And then we call apply to convert the remaining number values to ints.

For instance, we write

df.col = df.col.dropna().apply(lambda x: str(int(x)) )

to call dropna to drop the NaN values from the col column.

Then we call apply with a lambda function that calls int with x to convert x to an int.

And then we call str to convert the int to a string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *