Appending Pandas dataframe to sqlite table by primary key

后端 未结 2 1348
青春惊慌失措
青春惊慌失措 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: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()
    

提交回复
热议问题