I am trying to push data from excel file to sql_server express management studio 2008 using pandas and pyodbc, as I need to push data by creating a table in a database myDB
and here's my code
import pyodbc
import pandas as pd
import os
import sqlalchemy
from sqlalchemy import create_engine
# connect db
engine = create_engine('mssql+pyodbc://WWX542337CDCD\SMARTRNO_EXPRESS/myDB?driver=SQL+Server+Native+Client+11.0')
cursor = engine.raw_connection().cursor()
mydir = (os.getcwd()).replace('\\', '/') + '/'
lte_details = pd.read_excel(r'' + mydir + 'MNM_Rotterdam_5_Daily_Details-20191216081027.xlsx', sheet_name='LTE Details')
lte_details.columns = lte_details.columns.str.replace(' ', '')
# reading and insert one file at a time
for file in os.listdir('.'):
# only process excels files
file_basename, extension = file.split('.')
if extension == 'xlsx':
lte_details.to_sql(file_basename.lower(), con=engine.connect(), if_exists='replace')
and I find this error:
Traceback (most recent call last):
File "C:/Users/mwx825326/PycharmProjects/MyReference/test.py", line 22, in <module>
file_basename, extension = file.split('.')
ValueError: not enough values to unpack (expected 2, got 1)
and this is my connection
Any one have any idea how to solve this issue?