我想使用带有Python3的sqlite3将pd数据帧插入数据库

df = pd.DataFrame(maindatatable)
print (df)

con = sqlite3.connect(host="localhost",user="milenko",passwd="******",db="dbase")
sql.write_frame(df, con=con, name='table_name_for_df', if_exists='replace', flavor='mysql')

It doesn't work
  File "b23.py", line 36, in <module>
    con = sqlite3.connect(host="localhost",user="milenko",passwd="*******",db="dbase")
TypeError: Required argument 'database' (pos 1) not found


如果我回到MySQL

show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ap1                |
| classicmodels      |
| dbase              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+


dbase在这里,那怎么了?

如果我更改为

con = sqlite3.connect("dbase")


然后

AttributeError: module 'pandas.io.sql' has no attribute 'write_frame'

最佳答案

sqlite3.connect("dbase")

只需使用此行,就不需要所有这些

08-04 06:36