title: Function to check type datetime for cells in pandas
body: <p>I have a large data set with two datetime columns and as I’m trying to clean it, I created a function that apply to each cell of these two columns:</p>
  <pre><code>#dropoff_datetime
  def date_time_dropoff(cell):
      if pd.isnull(cell) == True:
          return('Missing Date Time dropoff')
      elif type(cell) == datetime.datetime:
          return ('Clean Date Time dropoff')
      elif type(cell) != datetime.datetime:
          return ('Type error Date Time dropoff')
  </code></pre>
  <p>When I run it first time on my dataframe, it returns that the cells have the wrong type (indeed, I see that it is of type object when I use df.dtypes). So next I convert the df using pandas method:</p>
  <pre><code>df2['Statue_dropoff_datetime'] = df['dropoff_datetime'].apply(date_time_dropoff)
  </code></pre>
  <p>and run the function again, but it stills return Type error  because it is not type datetim.datetime. However, once I use df.dtypes after the conversion I obtain the correct datetimetype:</p>
  <p><code>dropoff_datetime        datetime64[ns]</code></p>
  <p>Without success, I tried answers suggested for similar questions dealing with convesion, mainly:
  <a href="https://stackoverflow.com/questions/51898826/converting-object-column-in-pandas-dataframe-to-datetime">Converting object column in pandas dataframe to datetime</a>
  <a href="https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime">Convert Pandas Column to DateTime</a>
  <a href="https://stackoverflow.com/questions/38333954/converting-object-to-datetime-format-in-python">Converting object to datetime format in python</a>
  <a href="https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas">How to change the datetime format in pandas</a></p>
  <p>Btw, when I import at the beginning, I use:
  <code>import datetime</code></p>
  <p>Here's my df:</p>
  <pre><code>dropoff_datetime
  2020-06-10 11:16:00
  2020-06-21 11:53:06
  2020-06-09 13:25:21
  2020-06-01 19:06:05
  
  #dropoff_datetime
  def date_time_dropoff(cell):
      if pd.isnull(cell) == True:
          return('Date Time dropoff missing')
      elif type(cell) == datetime:
          return ('Date Time dropoff clean')
      elif type(cell) != datetime:
          return ('Date Time dropoff Type error')
  
  df1[‘Statue_dropoff_datetime'] = df['dropoff_datetime'].apply(date_time_dropoff)
  </code></pre>
  <p>and when I print:</p>
  <pre><code>print(pd.value_counts(df1.values.ravel()))
  Type error Date Time dropoff    47703
  </code></pre>
  <p>while using <code>df.dtypes</code> gives:</p>
  <pre><code>df.dtypes
  dropoff_datetime        datetime64[ns]
  </code></pre>