title: how to delete wrong row from dataframe when get ValueError by using astype
body: <p>I use pandas's astype function to parse a string into data in datetime64[ns] format, but because there are some outliers in the original data, it causes the program to go wrong.</p>
  
  <p>I want to get the wrong data index from the ValueError exception and delete the index data，rather than interrupt the program because of ValueError.Or is there any other way to achieve my goal?</p>
  
  <p>when parsing datetime by astype, I got a the following error prompts. I want to get the wrong data index from the ValueError exception and delete the index data.：</p>
  
  <pre><code>  File "/home/xiaopeng/anaconda3/envs/tensorflow/lib/python3.5/site-packages/pandas/core/dtypes/cast.py", line 636, in astype_nansafe
      return arr.astype(dtype)
  ValueError: Error parsing datetime string "2017-06-01VERSION=1.0" at position 10
  </code></pre>
  
  <p>the code as follows， the main function of this function is to read data from the text file, and to parse the data:</p>
  
  <pre><code>def file_to_df(file):
      print('converting file:%r(%r MB)' %(file,(os.path.getsize(file)/(1024*1024))))
  
      df = pd.read_csv(file, sep='\t', header=None, names=columns)
  
      for k in df.columns:
          _, df[k] = df[k].astype(str).str.split('=',1).str
  
      df = df[columns_use]
  
      # startswith() ,delete the wrong data when startswith is not '20'
      df = df[df['PASSTIME'].astype(str).str.startswith("20")]
  
      print('Log: Get %r number of data' % len(df))
  
      df['PASSTIME'] = df['PASSTIME'].astype(str).str.replace(' ', '?', n=1)
      df['PASSTIME'] = df['PASSTIME'].astype(str).str.replace(' ', '.', n=1)
      df['PASSTIME'] = df['PASSTIME'].astype(str).str.replace('?', ' ', n=1)
  
      df['PASSTIME'] = df['PASSTIME'].astype('datetime64[ns]')
  
      return df
  </code></pre>
  
  <p>and the Parsing error data as follows:</p>
  
  <pre><code>VERSION=1.0 PASSTIME=2017-06-01 11:01:46 625    CARSTATE=1  ...
  VERSION=1.0 PASSTIME=2017-06-01VERSION=1.0  PASSTIME=2017-06-01 11:04:02 618    CARSTATE=1  ...
  VERSION=1.0 PASSTIME=2017-06-01 11:04:49 595    CARSTATE=1  ...
  </code></pre>