Python data frame's processing of nan and None

Problem: Sometimes when python imports data from a file or database into a data frame, some null values ​​will be replaced with nan, and some will be replaced with None (it seems that column values ​​are all empty or character types will be replaced with None, column values If it is a value, it will be replaced by nan). What should be done at this time?

It is recommended to replace all None with nan, because there are more functions to deal with nan in np and pandas, use the statement:

df=df.fillna(value=np.nan)

After that, only need to judge whether a certain value number is nan, instead of worrying about None, use:

np.isnan(number)

Determine whether number is nan

 

the above.

Guess you like

Origin blog.csdn.net/jccc39/article/details/114235212