所以你需要1
if not missing value else 0
,所以可能的解决方案是 test not missing values bySeries.notna
并将其转换为0, 1
:
#if possible `NaN` is string convert to missing values
a = a.replace('NaN', np.nan)
a['Disease'] = a['Beat'].notna().astype(int)
a['Disease'] = a['Beat'].notna().view('i1')
a['Disease'] = np.where(a['Beat'].notna(), 1, 0)
a['Disease'] = np.where(a['Beat'].isna(), 0, 1)
样品:
a = pd.DataFrame({'Beat': [np.nan, 5, np.nan]})
#e.g. this solution, all working same
a['Disease'] = np.where(a['Beat'].isna(), 0, 1)
print (a)
Beat Disease
0 NaN 0
1 5.0 1
2 NaN 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句