It's similar to this, but the solution doesn't solve my problem.
I use pandas's astype function to parse a string into data in int32 format, but because there are some outliers in the original data, it causes ValueError exception.
I want to delete the wrong row data.
my code is:
df['DRIVEDIR'] = df['DRIVEDIR'].astype('int32')
the df (a small subset) is:
DRIVEDIR
PASSTIME
2017-06-02 11:01:08.247000+08:00 3
2017-06-02 11:00:55.710000+08:00 2
2017-06-02 11:00:41.139000+08:00 鲁XXX
2017-06-02 07:43:41.818000+08:00 2
2017-06-02 11:04:21.317000+08:00 3
2017-06-02 11:04:18.460000+08:00 2
2017-06-02 11:04:13.159000+08:00 1
I try use df['DRIVEDIR'] = df['DRIVEDIR'].astype('int32',errors= 'ignore'), but it can't change the dtype form object to int32, there's no way I can deal with it later.so, how to delete wrong row from dataframe when get ValueError by using astype from object to int32.
pd.to_numeric(df.DRIVEDIR, errors='coerce')