Python 从excel工作表中的每个标题行中切片列名,并在工作表名称中循环';熊猫身上的昆虫

Python 从excel工作表中的每个标题行中切片列名,并在工作表名称中循环';熊猫身上的昆虫,python,excel,pandas,slice,Python,Excel,Pandas,Slice,我试图从一个excel文件中插入数据,该文件包含多个工作表,每个工作表的名称在数据库中都有对应的表。现在我想的一种方法是在工作表名称上循环,并在一个循环中创建一个用于所有工作表名称的递归SQL。现在在循环中,假设第一个工作表名出现,则很少检查数据库中是否存在表,并验证工作表中的列名以及数据库中的列名。如果一切正常,则会将图纸数据插入数据库 我面临的挑战是: 1-从pandas获得Sheetname xls = pd.ExcelFile<filepath>

我试图从一个excel文件中插入数据,该文件包含多个工作表,每个工作表的名称在数据库中都有对应的表。现在我想的一种方法是在工作表名称上循环,并在一个循环中创建一个用于所有工作表名称的递归SQL。现在在循环中,假设第一个工作表名出现,则很少检查数据库中是否存在表,并验证工作表中的列名以及数据库中的列名。如果一切正常,则会将图纸数据插入数据库

我面临的挑战是:

1-从pandas获得Sheetname

        xls = pd.ExcelFile<filepath>
        Sheet_name = x.sheet_names

I am not able to loop through it although it contains all the sheet name but for() is not working.
Help me with a iteration code.
代码:

关于(1)

read\u excel
函数的
sheet\u name
参数可以是
None
。执行此操作时,返回值将不是数据帧,而是字典。它的键将是工作表名称和数据帧本身的值

然后,您可以遍历该词典并进行检查

I am placing a few piece of code that i have been working on, help me with syntax error's as well

Their are errors in SQL code as well Please help me with them also
import pandas as pd
Import the oracle lib

Create -----> DB_Connection 
mycursor = DB_Connection.cursor()
xls = pd.ExcelFile('File Path')
SheetNames = xls.sheet_names

for i in SheetNames:
    SelectSql = "SELECT TABLE_NAME FROM all_tab_columns where OWNER = 'XYZZZ' and TABLE_NAME = '"i"' "
    mycursor.execute(SelectSql)
    QueryResult = mycursor.fethcone()

if(pd.isnull(QueryResult)):
    Print("Table doesn't exist in database")
else:
    """    Add the Data frame slicing code to get Column name's to Check if same Exist in Database or Not    """
    
    GetColumnSql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '"i"' ORDER BY ORDINAL_POSITION"
    mycursor.execute(GetColumnSql)
    ColumnName = mycursor.fetchall()
    
    InsertSql = "INSERT INTO '"i"'('"ColumnName"') VALUES(%s,%s,%s,%s,%s)"
    VAL0 = """  insert from dataframe  """
    mycursor.execute(InsertSql,VAL0)
    
    DB_Connection.commit();