Python TypeError:无法将DatetimeIndex强制转换为dtype datetime64[us]

Python TypeError:无法将DatetimeIndex强制转换为dtype datetime64[us],python,pandas,Python,Pandas,TypeError:无法将DatetimeIndex强制转换为dtype datetime64[us] import time import pandas as pd import sqlalchemy from sqlalchemy import create_engine import psycopg2 engine1 = create_engine('postgresql://postgres:postgres@localhost:5432/db1') engine2 = create_e

TypeError:无法将DatetimeIndex强制转换为dtype datetime64[us]

import time
import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
import psycopg2
engine1 = create_engine('postgresql://postgres:postgres@localhost:5432/db1')
engine2 = create_engine('postgresql://postgres:postgres@localhost:5432/db2')
df = pd.read_sql_query("""
select id,text,created_date,is_read,to_user_id,is_new,url,text_ar,text_en from notifications_notification where created_date <= NOW() - interval '1 month'""",engine1)

 df= df.rename(columns={  'id':'original_id','text':'text','created_date':'created_date','is_read':'is_read','to_user_id':'to_user_id','is_new':'is_new','url':'url','text_ar':'text_ar','text_en':'text_en'})

df.index = df.index.values.astype('datetime64[us]')                                          

df.to_sql(name='notifications_notification_archive',con=engine2,if_exists='append')
导入时间
作为pd进口熊猫
进口炼金术
从sqlalchemy导入创建引擎
导入psycopg2
engine1=创建引擎('postgresql://postgres:postgres@本地主机:5432/db1')
engine2=创建引擎('postgresql://postgres:postgres@localhost:5432/db2')
df=pd.read\u sql\u查询(“”)

选择id、text、created_date、is_read、to_user_id、is_new、url、text_ar、text_en from notification\u notification where created_dateFixed现在我使用了以下几行:

df['created_date'] = pd.to_datetime(df['created_date'])
df['created_date'] = df['created_date'].astype('datetime64[us]')
df.set_index('created_date', inplace=True)
df.to_sql(name='notifications_notification_archive',con=engine2,if_exists='append')

你确定这是一个
类型错误
而不是
值错误
?那么如何修复它?你能帮忙吗?这是一个值错误吗?这是一个类型错误你有一个非数字索引,熊猫无法转换为日期。试着将它更改为其他内容?