用橙色的Python脚本构件创建cumsum列
问题描述:
我无法创建另一个累积和的新列。 如果你是像我这样的Python新手,橙色文档是难以理解的。用橙色的Python脚本构件创建cumsum列
这是代码我在我的Python脚本的Widget
import numpy as np
## make a copy from the data that widget recieves
out_data = in_data.copy()
## compute cumulative sum of column values
newCumsumColValues = np.cumsum(out_data[:,('myCumsumcolTarget')])
## i got the values
print(newCumsumColValuesl)
## i need to create a new column with the values in out_data
## i've tried to update column values first to test
## with an static value column values updated to 8
out_data[:,'myCumsumcolTarget'] = 8
## with newCumsumColValue is NOT working
out_data[:,'myCumsumcolTarget'] = newCumsumColValues
这些例子不难理解了我:
https://docs.orange.biolab.si/3/visual-programming/widgets/data/pythonscript.html https://docs.orange.biolab.si/3/data-mining-library/tutorial/data.html#exploration-of-the-data-domain
在此先感谢, 文斯。
答
尝试:
out_data.X[:, i] = newCumsumColValues
其中i
是
out_data.domain.index(out_data.domain['myCumsumcolTarget'])
此代码是有点复杂,但它的工作原理。
非常感谢你@Matphy,完美的作品。你说得对,有点复杂。问候。 – Vince