Python ValueError:以10为基数的int()的文本无效:';待定';

Python ValueError:以10为基数的int()的文本无效:';待定';,python,pandas,openpyxl,valueerror,Python,Pandas,Openpyxl,Valueerror,我正试图更新现有的xlsm文件,具体取决于dataframe值rows,方法是使用pandasdf的代码通知excl文件中我要更新的列 frm_mwfy_to_te_col = pd.read_excel(r'' + mydir + 'Governance_Tracker - Copy - Copy.xlsm', usecols=['Pending ', 'Pending Status'], header=1, axis=1

我正试图更新现有的
xlsm
文件,具体取决于
dataframe
rows
,方法是使用
pandas
df的代码通知excl文件中我要更新的列

frm_mwfy_to_te_col = pd.read_excel(r'' + mydir + 'Governance_Tracker - Copy - Copy.xlsm',
                                   usecols=['Pending  ', 'Pending Status'], header=1, axis=1)
这是我代码中出错的部分

for index, row in filtered_data_cond1['SiteCode'].items():
    for col, _ in frm_mwfy_to_te_col.items(): ws.cell(row=index + 3,
                                                      column=int(col)).value = 'Value1', 'Value2'
因为
过滤的数据\u cond1['SiteCode']
是我要更新的行

filtered_data_cond1 = all_data.loc[all_data['SiteCode'].str.contains('|'.join(frm_mwfy_to_te.Subject))]
这是我的
所有数据

all_data = pd.read_excel(r'' + mydir + 'Governance_Tracker - Copy - Copy.xlsm'
                         , header=1).drop(['#'], axis=1)
我发现了这个错误

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/MyALLRefProf/MyExp.py", line 54, in <module>
    column=int(col).isnull()).value = 'Value1', 'Value2'  # example
ValueError: invalid literal for int() with base 10: 'Pending
回溯(最近一次呼叫最后一次):
文件“C:/Users/DELL/PycharmProjects/MyALLRefProf/MyExp.py”,第54行,在
column=int(col).isnull()).value='Value1','Value2'#示例
ValueError:基数为10的int()的文本无效:“挂起”

错误在于,
frmwfy\u to\u te\u col
数据框中的列(根据我收集的数据)称为
'Pending'
'Pending Status'
。当您在该行代码中尝试
int(col)
时,您正试图将字符串
'Pending'
转换为
int
,这是无法完成的

可能尝试将列重命名为整数。或者,更好的是,修改您的逻辑,以允许列名以一种更具python风格的方式成为字符串

编辑:

尝试将代码的问题部分更改为:

for index, row in filtered_data_cond1['SiteCode'].items():
    for col_num in range(len(frm_mwfy_to_te_col.columns)): 
        ws.cell(row=index + 3, column=col_num + 1).value = 'Value1', 'Value2'

非常感谢您的支持,所以我不需要重命名列I,那么我如何使用逻辑将列名转换为字符串呢?我对行使用了相同的方法,效果很好,但对
标题
@DevyToly,它不适用于最新的编辑是否有帮助。我不确定您是否需要
we.cell()
的列名或列的位置。@DevyToly好的,我现在就给您。请尝试最新的编辑。您可能需要在
colu num
中添加一个偏移量,类似于您在
+3
行中所做的,以使其与excel工作表匹配。@您可以尝试在
colu num
中添加1。