gpt4 book ai didi

mysql - 1054,字段列表中的未知列 'index'

转载 作者:行者123 更新时间:2023-12-04 02:36:52 25 4
gpt4 key购买 nike

df_row.head()
identifier link likes_count company
0 2292512316069378197 https://www.instagram.com/p/B_Qo84ihfiV 9608 Ralph Lauren
1 2292462538514040606 https://www.instagram.com/p/B_QdohlBQce 9462 Ralph Lauren
2 2292418655784545069 https://www.instagram.com/p/B_QTp8mhCst 22033 Ralph Lauren
3 2292372137723669561 https://www.instagram.com/p/B_QJFBSBaw5 14112 Ralph Lauren
4 2292334760619881771 https://www.instagram.com/p/B_QAlHJBzUr 5974 Ralph Lauren

# import the module
from sqlalchemy import create_engine

# create sqlalchemy engine
engine = create_engine("mysql+pymysql://{user}:{pw}@localhost{db}"
.format(user="admin",
pw="abcdef",
db="ghi"))
df_row.to_sql('df_row', con = engine, if_exists = 'append', chunksize = 1000)

当我运行上面的代码时,会出现以下消息:InternalError: (pymysql.err.InternalError) (1054, "'field list'中的未知列'index'")

最佳答案

df_row.to_sql('df_row', con = engine, if_exists = 'append', chunksize = 1000)

改成

df_row.to_sql('df_row', con = engine, if_exists = 'append', chunksize = 1000, index= False)

存在于数据框中的索引。所以默认的 to_sql 会尝试插入到表中。但表中不存在该列,因此添加 index = false 会有所帮助。

关于mysql - 1054,字段列表中的未知列 'index',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61367451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com