Numpy isnan() fails on an array of floats (from pandas dataframe apply)

后端 未结 4 1033
清酒与你
清酒与你 2020-11-30 21:04

I have an array of floats (some normal numbers, some nans) that is coming out of an apply on a pandas dataframe.

For some reason, numpy.isnan is failing on this arra

4条回答
  •  Happy的楠姐
    2020-11-30 21:37

    On top of @unutbu answer, you could coerce pandas numpy object array to native (float64) type, something along the line

    import pandas as pd
    pd.to_numeric(df['tester'], errors='coerce')
    

    Specify errors='coerce' to force strings that can't be parsed to a numeric value to become NaN. Column type would be dtype: float64, and then isnan check should work

提交回复
热议问题