user1827356
user1827356

Reputation: 7022

Pandas to_datetime produces inconsistent dates

to_datetime seems to produce different base dates (pandas-0.12.0)

pd.to_datetime('03:00:00.017158433')
Timestamp('2013-10-22 03:00:00.017158', tz=None)

pd.to_datetime(10800017158433, unit='ns')
Timestamp('1970-01-01 03:00:00.017158433', tz=None)

Is this a bug? Or is it an issue with usage?

Upvotes: 0

Views: 331

Answers (1)

Jeff
Jeff

Reputation: 129078

It IS correct, but its in nano-seconds from epoch, (e.g. 19700101 00:00:00)

In [3]: pd.to_datetime('03:00:00.017158433')
Out[3]: Timestamp('2013-10-22 03:00:00.017158', tz=None)

In [4]: pd.to_datetime('03:00:00.017158433').value
Out[4]: 1382410800017158000

In [5]: pd.to_datetime(1382410800017158000,unit='ns')
Out[5]: Timestamp('2013-10-22 03:00:00.017158', tz=None)

where is 10800017158433 from

its not a valid epoch time stamp (well it is, but its probably not what you want)

You stated that this is from midnight, so you can do this.

In [2]: Timestamp(Timestamp('20131022').value+10800017158433)
Out[2]: Timestamp('2013-10-22 03:00:00.017158433', tz=None)

Upvotes: 2

Related Questions