Python sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)can';t适应类型';dict';

Python sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)can';t适应类型';dict';,python,python-3.x,database,amazon-redshift,Python,Python 3.x,Database,Amazon Redshift,我正在使用以下代码行尝试使用pandas大容量插入到redshift数据库 df.to_sql(table_name, conn, index=False, if_exists='replace') 获取以下错误 cursor, statement, parameters, context File "/home/ubuntu/trell/env/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/psycop

我正在使用以下代码行尝试使用pandas大容量插入到redshift数据库

df.to_sql(table_name, conn, index=False, if_exists='replace')
获取以下错误

       cursor, statement, parameters, context
  File "/home/ubuntu/trell/env/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 854, in do_executemany
    cursor.executemany(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'dict'
[SQL: INSERT INTO events_20180625 (event_date, event_timestamp, event_name, event_params, event_previous_timestamp, user_pseudo_id, user_properties, user_first_touch_timestamp, device, geo, app_info, traffic_source, stream_id, platform) VALUES (%(event_date)s, %(event_timestamp)s, %(event_name)s, %(event_params)s, %(event_previous_timestamp)s, %(user_pseudo_id)s, %(user_properties)s, %(user_first_touch_timestamp)s, %(device)s, %(geo)s, %(app_info)s, %(traffic_source)s, %(stream_id)s, %(platform)s)]
[parameters: ({'event_date': '20180625', 'event_timestamp': '1529948530245005', 'event_name': 'firebase_campaign', 'event_params': '{"medium": "(not set)", "firebase_event_origin": "app", "source": "(not set)", "firebase_screen_class": "TaleEmotionTagActivity", "item_name": "NARRA ... (24 characters truncated) ... ory": "Create Post", "error_value": "Festivals Around the World_CT", "firebase_previous_class": "TrailListActivity", "previous_app_version": "3.1.0"}', 'event_previous_timestamp': '1529948527702005', 'user_pseudo_id': 'ffb01b060c860317c9baba657ffe402d', 'user_properties': '{"first_open_time": "1529172000000", "first_open_time_set_timestamp_micros": "1529171511734000"}', 'user_first_touch_timestamp': '1529948488186000', 'device': {'category': 'mobile', 'mobile_brand_name': 'Samsung', 'mobile_model_name': 'SM-A500G', 'mobile_marketing_name': 'Galaxy A5', 'mobile_os_hardware_mode ... (81 characters truncated) ... ', 'advertising_id': '44f5dd05-1f78-461a-be16-f6c4b1665920', 'language': 'en-gb', 'is_limited_ad_tracking': 'No', 'time_zone_offset_seconds': '19800'}, 'geo': {'continent': 'Asia', 'country': 'India', 'region': 'Gujarat', 'city': 'Ahmedabad'}, 'app_info': {'id': 'app.trell', 'version': '3.3.8', 'firebase_app_id': '1:808772988865:android:8db93cca16602100', 'install_source': 'com.android.vending'}, 'traffic_source': {'name': '(direct)', 'medium': '(none)', 'source': '(direct)'}, 'stream_id': '1051639513', 'platform': 'ANDROID'}, 
尝试跟踪具有字典值的列,但仍然得到相同的上述错误

df['event_params'] = list(map(lambda x: json.dumps(x), df['event_params']))
df['user_properties'] = list(map(lambda x: json.dumps(x), df['user_properties']))

任何线索高度赞赏。谢谢。

看起来您还有许多其他列,其中的值是字典,例如
设备
地理
应用程序信息
,以及
流量
。也许可以尝试对这些进行同样的操作,并检查错误是否消失。看起来您还有许多其他列的值都是字典,例如
设备
地理
应用程序信息
,以及
交通源
。也许试着用这些做同样的事情,看看错误是否消失了。