pymysql 并将 Pandas 数据帧写回 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20205396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pymysql and writing a pandas dataframe back to MySQL
提问by mpg
I am in Python and have a Pandas dataframe called Office_RX.
我使用 Python 并且有一个名为 Office_RX 的 Pandas 数据框。
I am connected to mysql via pymysql.
我通过pymysql连接到mysql。
conn = pymysql.connect(host='127....', port=3306, user='root', passwd='', db='ABCD')
c = conn.cursor()
I want to write the Office_RX dataframe back into the MYSQL db I am connected to.
我想将 Office_RX 数据帧写回我连接的 MYSQL 数据库。
I am using this code:
我正在使用此代码:
sql.write_frame(Office_RX, conn=conn, name='Office_RX', if_exists='replace', flavor='mysql')
But I get the error: TypeError: write_frame() takes at least 3 arguments (4 given)
但我收到错误:TypeError: write_frame() 需要至少 3 个参数(给出 4 个)
Can tell what I am doing wrong. Suggestions?
可以告诉我做错了什么。建议?
采纳答案by Andy Hayden
The argument in write_frameis con rather than conn:
中的参数write_frame是 con 而不是 conn:
sql.write_frame(Office_RX, con=conn, name='Office_RX', if_exists='replace', flavor='mysql')
This function accepts **kwargs, hence the vaguely cryptic error message.
此函数接受**kwargs,因此是含糊不清的错误消息。

