I am trying to create a function that will accept a dataframe and will parse that dataframe into a sql server table.
I am stuck as to what needs go in the select statement below the insert query.
df- dataframe
desttable - destination table that needs to be parsed.
tablecols - An array of the table columns for the table
# Insert DataFrame to Table def InsertintoDb(self, df, desttable, tablecols): tablecolnames = ','.join(tablecols) qmark = ['?' for s in tablecols] allqmarks = ','.join(qmark) #rowappendcolname = ','.join(['row.' + s for s in tablecols]) for index, row in df.iterrows(): cursor.execute( '''INSERT INTO [Py_Test].[dbo].''' + desttable + ''' ( ''' + tablecolnames + ''')VALUES (''' + allqmarks + ''')''', ) self.conn.commit()
Any help is much appreciated.