ValueError: Cannot cast DatetimeIndex to dtype datetime64[us]

前端 未结 3 1921
情话喂你
情话喂你 2021-02-20 06:53

I\'m trying to create a PostgreSQL table of 30-minute data for the S&P 500 ETF (spy30new, for testing freshly inserted data) from a table of several stocks with 15-minute da

3条回答
  •  死守一世寂寞
    2021-02-20 07:26

    Using pd.to_datetime() on each element worked. Option 4, which doesn't work, applies pd.to_datetime() to the entire series. Perhaps the Postgres driver understands python datetime, but not datetime64 in pandas & numpy. Option 4 produced the correct output, but I got ValueError (see title) when sending the DF to Postgres

    timesAsPyDt = (spy0030Df['dt']).apply(lambda d: pd.to_datetime(str(d)))
    

提交回复
热议问题