我试图根据dataframe
值rows
更新现有的xlsm
文件,方法是使用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'
因为filtered_data_cond1['SiteCode']
是我要更新的行
filtered_data_cond1 = all_data.loc[all_data['SiteCode'].str.contains('|'.join(frm_mwfy_to_te.Subject))]
这是我的all_data
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
'
错误是
frm_mwfy_to_te_col
数据帧中的列(据我所知)称为'Pending '
和'Pending Status'
。当您在那行代码中尝试int(col)
时,您正在尝试将字符串'Pending '
强制转换为int
,这是不可能的。你知道吗可能尝试将列重命名为整数。或者,更好的是,修改您的逻辑,使列名以一种更为python的方式成为字符串。你知道吗
编辑:
尝试将代码的问题部分更改为:
相关问题 更多 >
编程相关推荐