Appending Pandas dataframe to sqlite table by primary key

后端 未结 2 1338
青春惊慌失措
青春惊慌失措 2020-12-09 19:13

I want to append the Pandas dataframe to an existing table in a sqlite database called \'NewTable\'. NewTable has three fields (ID, Name, Age) and ID is the primary key. My

相关标签:
2条回答
  • 2020-12-09 19:23

    http://pandas.pydata.org/pandas-docs/version/0.13.1/generated/pandas.io.sql.write_frame.html

    curious if you tried replace?

    if_exists: {‘fail’, ‘replace’, ‘append’}, default ‘fail’
    
    0 讨论(0)
  • 2020-12-09 19:37

    You can use SQL functionality insert or replace

    query=''' insert or replace into NewTable (ID,Name,Age) values (?,?,?) '''
    conn.executemany(query, test.to_records(index=False))
    conn.commit()
    
    0 讨论(0)
提交回复
热议问题