title: A dataset with Int64, Float64 and datetime64[ns] gets converted to object after applying Pandas fillna method
body: <p>I am using Kaggle's dataset (<a href="https://www.kaggle.com/datasets/claytonmiller/lbnl-automated-fault-detection-for-buildings-data" rel="nofollow noreferrer">https://www.kaggle.com/datasets/claytonmiller/lbnl-automated-fault-detection-for-buildings-data</a>)</p>
  <p>I have A dataset with Int64, Float64, and datetime64[ns] datatypes; after using the pandas fillna method, however, all of my data type changes to object datatype.</p>
  <p>Could anyone assist me with what I need to do to retain the original data types after the Pandas conversion?</p>
  <p>The following is the code I use:</p>
  <pre><code>import pandas as pd
  import datetime as dt
  %matplotlib inline
  df = pd.read_csv('RTU.csv') 
  df['Timestamp'] = pd.to_datetime(df['Timestamp'])
  </code></pre>
  <p><a href="https://i.stack.imgur.com/7OGIu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7OGIu.png" alt="The data types initally" /></a></p>
  <p>If I do a <code>df.dtypes</code> I can see the correct datatypes however, after the following lines of code, it changes to object datatype.</p>
  <pre><code>df['Timestamp'] = pd.to_datetime(df['Timestamp'])
  def fault_mapper_FD(faultDate):
      if pd.Timestamp(2017, 8, 27, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 8, 28, 0):
          return 0
      if pd.Timestamp(2017, 8, 29, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 8, 29, 23, 59):
          return 0
      if pd.Timestamp(2017, 12, 1, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 1, 23, 59):
          return 0
      if pd.Timestamp(2017, 12, 3, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 3, 23, 59):
          return 0
      if pd.Timestamp(2017, 12, 7, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 8, 0):
          return 0
      if pd.Timestamp(2017, 12, 14, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 14, 23, 59):
          return 0
      if pd.Timestamp(2018, 2, 7, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 7, 23, 59):
          return 0
      if pd.Timestamp(2018, 2, 9, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 9, 23, 59):
          return 0
      if pd.Timestamp(2017, 12, 20, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 20, 23, 59):
          return 0
      if pd.Timestamp(2018, 2, 18, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 18, 23, 59):
          return 0
      if pd.Timestamp(2018, 2, 1, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 1, 23, 59):
          return 0
      if pd.Timestamp(2018, 1, 31, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 1, 31, 23, 59):
          return 0
      if pd.Timestamp(2018, 1, 28, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 1, 28, 23, 59):
          return 0
      if pd.Timestamp(2018, 1, 27, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 1, 27, 23, 59):
          return 0
      if (pd.Timestamp(2017, 9, 1, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 9, 1, 23, 59) or 
      pd.Timestamp(2017, 11, 30, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 11, 30, 23, 59) or 
      pd.Timestamp(2017, 12, 9, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 9, 23, 59) or 
      pd.Timestamp(2017, 12, 10, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 11, 0) or 
      pd.Timestamp(2017, 12, 24, 0) &lt;= faultDate &lt;= pd.Timestamp(2017, 12, 24, 23, 59) or 
      pd.Timestamp(2018, 2, 4, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 4, 23, 59) or 
      pd.Timestamp(2018, 2, 5, 0) &lt;= faultDate &lt;= pd.Timestamp(2018, 2, 6, 0)):
          return 1
  
  df['FD'] = df['Timestamp'].apply(lambda fault_date: fault_mapper_FD(fault_date))
  
  cond = (df.Timestamp.dt.time &gt; dt.time(22,0)) | ((df.Timestamp.dt.time &lt; dt.time(7,0)))
  df[cond] = df[cond].fillna(0,axis=1)
  </code></pre>
  <p>Now the <code>df.dtypes</code> gives all of my columns as objects/</p>
  <p><a href="https://i.stack.imgur.com/D3aUY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D3aUY.png" alt="The data types after the Pandas fillna methos" /></a></p>