Checking row by row if a value is of the type int in a dataframe and selecting incorrect rows

Viewed 585

I have the following data frame (just a subset):

Time
0 66
1 91

I want to check row by row to validate if values under time column are of type int. If they are not, then save that incorrect row in a new data frame. I have spent days but cannot figure out how to do this.

2 Answers
df = pd.DataFrame({'Time': [66, '91']})
new_df = df[(df['Time'].map(type) != int)]

    Time
1   91

You can use the Pandas function pd.api.types.is_integer to test for integer type, as follows:

df = pd.DataFrame({'Time': [66, '91', 1.23, 'a', 0.0, '', np.nan, 77]})

non_int_df = df[~df['Time'].map(pd.api.types.is_integer)]

print(non_int_df)


   Time
1    91
2  1.23
3     a
4   0.0
5      
6   NaN
Related