Convert date column in dataframe to ticks in python
<p>Good day</p>

<p>I have a pandas dataframe with 3 columns. Column two is in date format yyyy-mm-dd but I would like to convert these to ticks. I would like to know the most efficient way to do this (i.e. I don't want to loop through each row).</p>

<p>My code is as follows:</p>

<pre><code>#Example of getting ticks
import time;  # This is required to include time module.

ticks = time.time()
print("Number of ticks since 12:00am, January 1, 1970:", ticks)

#Example of converting to ticks

import datetime
s = "01/12/2015"
time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())

#My code

import numpy as np
import pandas as pd

path = "C:/Users/geoff/OneDrive - Noble Brothers Consult (Pty) Ltd/Clients/GrAM/Daily Price Data/"
filename = "SST_5_Sept_2016_formatted.csv"
full_path = path + filename

data = pd.read_csv(full_path)

#here i need to convert the column data['Date'] to ticks
</code></pre>

<p>I have uploaded a screenshot my datafile as well:</p>

<p>Screenshot of datafile:</p>

<p><a href="http://i.stack.imgur.com/7FTTc.png" rel="nofollow"><img src="http://i.stack.imgur.com/7FTTc.png" alt="screenshot"></a></p>

<p>Thanks very much for your help.</p>

<p>First, wrap the converting-to-ticks part in a function, such as</p>

<pre><code>def convert_to_tic(s):
    return time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
</code></pre>

<p>Then, turn your column into a <code>DataFrame</code> and use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">apply</a>. Something in the likes of what is suggested in the bottom part of <a href="http://stackoverflow.com/questions/12604909/pandas-how-to-change-all-the-values-of-a-column">this answer</a></p>

python datetime time