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: Why are the ringwraiths fearful of coming in contact with water?
Answer: It is very plausible that it is a holdover of the power of Ulmo. See this forum thread for more...

http://forum.barrowdowns.com/archive/index.php?t-201.html