jiacheng1gujiaxin:

ValueError: cannot convert float NaN to integer


You can avoid this with a mask method. Note first that in python NaN is defined as the number which is not equal to itself:
>float('nan') == float('nan')      
False

It might be worth avoiding use of np.NaN altogether. NaN literally means “not a number”, and it cannot be converted to an integer.  In general, Python prefers raising an exception to returning NaN, so things like sqrt(-1) and log(0.0) will generally raise instead of returning NaN. However, you may get this value back from some other library.  From v0.24, you actually can. Pandas introduces Nullable Integer Data Types which allows integers to coexist with NaNs.  Also, even at the lastest versions of pandas if the column is object type you would have to convert into float first, something like:
df['column_name'].astype(np.float).astype("Int32")
NB: You have to go through numpy float first and then to nullable Int32, for some reason.