I have a data frame df
which its index structure likes the following:
>> df.index.values
array(['2017-12-19T07:00:04.753422000', '2017-12-19T07:00:09.628389000',
'2017-12-19T07:00:12.065880000', ...,
'2018-01-22T15:29:52.462586000', '2018-01-22T15:29:54.900103000',
'2018-01-22T15:29:56.728234000'], dtype='datetime64[ns]')
As you can see dtype
of the index is datetime64[ns]
. How can I update its dtype
to datetime64[us]
? (this post did not work for me).
Indeed the main problem comes from calling this function df.to_sql('table_name', engine)
to insert df
into a table in postgre. And I've gotten the following errors:
error: Cannot cast DatetimeIndex to dtype datetime64[us]
And I can't solve the problem using these posts (1 and 2), as they did not help on index dtype
.