title: Pandas - Rounding off timestamps to the nearest second
body: <p>I am struggling to round off timestamps using pandas.</p>
  
  <p>The timestamps look like this:</p>
  
  <pre><code>datetime.datetime(2017,06,25,00,31,53,993000)
  datetime.datetime(2017,06,25,00,32,31,224000)
  datetime.datetime(2017,06,25,00,33,11,223000)
  datetime.datetime(2017,06,25,00,33,53,876000)
  datetime.datetime(2017,06,25,00,34,31,219000)
  datetime.datetime(2017,06,25,00,35,12,634000)
  </code></pre>
  
  <p>How do I round off to the nearest second?</p>
  
  <p>Previously iv tried suggestions in this post but they didn't work:
  <a href="https://stackoverflow.com/questions/47792242/rounding-time-off-to-the-nearest-second-python">Rounding time off to the nearest second - Python</a></p>
  
  <p>My code looks like this so far:</p>
  
  <pre><code>import pandas as pd
  filename = 'data.csv'
  readcsv = pd.read_csv(filename)
  </code></pre>
  
  <p><strong>Import data according to file header info</strong></p>
  
  <pre><code>log_date = readcsv.date
  log_time = readcsv.time
  log_lon = readcsv.lon
  log_lat = readcsv.lat
  log_heading = readcsv.heading
  
  readcsv['date'] = pd.to_datetime(readcsv['date']).dt.date
  readcsv['time'] = pd.to_datetime(readcsv['time']).dt.time
  </code></pre>
  
  <p><strong>Combine date and time into one variable</strong></p>
  
  <pre><code>timestamp = [datetime.datetime.combine(log_date[i],log_time[i]) for i in range(len(log_date))]
  </code></pre>
  
  <p><strong>Create dataframe</strong></p>
  
  <pre><code>data = {'timestamp':timestamp,'log_lon':log_lon,'log_lat':log_lat,'log_heading':log_heading}
  log_data = pd.DataFrame(data,columns=['timestamp','log_lon','log_lat','log_heading'])
  log_data.index = log_data['timestamp']
  </code></pre>
  
  <p>I am still quite new to python so please excuse my ignorance</p>