mikebmassey mikebmassey - 3 months ago 20
Python Question

How to handle microseconds with 7 decimal precision instead of 6

I am processing a csv in

(3.5) that has a date field in it. The date contains a microsecond precision of 7 rather than 6, which I believe is the max that
can handle.

Without stripping the field the last character, is there a way to make this a datetime object?

Here is the specific code:

d = '2015-07-03 17:29:34.5940379'
pd.datetime.strptime(d, '%Y-%m-%d %H:%M:%S.%f')
ValueError: unconverted data remains: 9

cco cco

If that's the format your numbers are in, just use pd.to_timestamp(d)

datetime.datetime objects only have microsecond resolution (6 digits), but Pandas Timestamps are Numpy datetime64 objects.