[英]Difference of two columns in Pandas dataframe
Hi I tring to get two columns from Excel and parse to a DataFrame, after that I need subtract this columns.嗨,我想从 Excel 中获取两列并解析为 DataFrame,之后我需要减去这些列。
This is my code这是我的代码
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))
Cross post in: https://python-forum.io/Thread-Difference-of-two-columns-in-Pandas-dataframe交叉帖子: https://python-forum.io/Thread-Difference-of-two-columns-in-Pandas-dataframe
One suggestion to make it work is to add condition index=False
to options
function.使其工作的一个建议是将条件
index=False
添加到options
function。
ndf = xw.Range('AI1:AJ' + str(len(last_row))).options(pd.DataFrame, index=False).value
xw
has parsed your column VC
as index, which caused KeyError
when you try to operate on that column. xw
已将您的列VC
解析为索引,当您尝试对该列进行操作时导致KeyError
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.