嗨,我尝试从Excel中获取两列并解析为一个数据帧,然后我需要减去这两列
这是我的密码
ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame).value
#Error in this line below
ndf['VC-BC'] = ndf['VC'] - ndf['BC']
#xw.Range("BH1").options(index=False).value = ndf
print(ndf.head(20))
交叉邮寄: https://python-forum.io/Thread-Difference-of-two-columns-in-Pandas-dataframe
一个建议是将条件
index=False
添加到options
函数中ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame, index=False).value
xw
已将您的列VC
解析为索引,这在您尝试对该列进行操作时导致KeyError
相关问题 更多 >
编程相关推荐