有一些值,无法将其转换为
int。
您可以使用
to_numeric并获得
NaN存在问题的价值:
df['Num_Detections'] = pd.to_numeric(df['Num_Detections'], errors='coerce')
如果需要检查值有问题的行,请
boolean indexing与mask配合使用
isnull:
print (df[ pd.to_numeric(df['Num_Detections'], errors='coerce').isnull()])
样品:
df = pd.Dataframe({'Num_Detections':[1,2,'a1']})print (df) Num_Detections0 11 22 a1print (df[ pd.to_numeric(df['Num_Detections'], errors='coerce').isnull()]) Num_Detections2 a1df['Num_Detections'] = pd.to_numeric(df['Num_Detections'], errors='coerce')print (df) Num_Detections0 1.01 2.02 NaN


