pandas invalid literal for long() with base 10 error pandas invalid literal for long() with base 10 error pandas pandas

pandas invalid literal for long() with base 10 error


There is some value, which cannot be converted to int.

You can use to_numeric and get NaN where is problematic value:

df['Num_Detections'] = pd.to_numeric(df['Num_Detections'], errors='coerce')

If need check rows with problematic values, use boolean indexing with mask with isnull:

print (df[ pd.to_numeric(df['Num_Detections'], errors='coerce').isnull()])

Sample:

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