I have ASCII files with a rather odd timestamp:

DATAH   DATE    TIME    SECONDS NANOSECONDS D
DATA    2012-06-04  23:49:15    1338853755  700000000   0.00855577
DATA    2012-06-04  23:49:15    1338853755  800000000   0.00805482
DATA    2012-06-04  23:49:15    1338853755  900000000   -0.00537284
DATA    2012-06-04  23:49:16    1338853756  0   -0.0239447


Basically the timestamp is divided into 4 columns - DATE, TIME, SECONDS and NANOSECONDS.
I'd like to read the file as a pandas DataFrame with DATE, TIME and NANOSECONDS as datetime objects, which are used as index:

import datetime as dt
import pandas as pd

parse = lambda x: dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S %f')

df = pd.read_csv('data.txt', sep='\t', parse_dates=[['DATE', 'TIME', 'NANOSECONDS']], index_col=0, date_parser=parse)


But this fails, because nanoseconds values have 9 digits instead of 6 as required by the %f format. The above code works if I manually remove the 3 extra zeroes from the values in NANOSECONDS column.
Could you please show me, how I can read-in the sample file as a pandas DataFrame object using DATE, TIME and NANOSECONDS columns as index?

[UPDATE] Using %f000 as suggested by behzad.nouri works if NANOSECONDS column doesn't contain 0 values. So, apparently this is what's causing the problem now.


Question: Will this work? hex edited a file and changed inet_aton to inet_pton
Answer: Do you think the python socket module will break in the future? 

Yes. inet-aton and inet_pton do not use the same number and type of arguments. Your code will likely break or at least dysfunction the first time this php function is called. If you (or a library you use) never call it, you are probably safe.