Search code examples
pythonmysqlpandaspymysql

pymysql and writing a pandas dataframe back to MySQL


I am in Python and have a Pandas dataframe called Office_RX.

I am connected to mysql via pymysql.

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.

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)

Can tell what I am doing wrong. Suggestions?


Solution

  • The argument in write_frame is con rather than 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.