代码之家  ›  专栏  ›  技术社区  ›  Vince

用橙色的Python脚本小部件创建cumsum列

  •  1
  • Vince  · 技术社区  · 7 年前

    如果你像我一样是Python新手,橙色文档很难理解。

    这是我在Python脚本小部件中的代码

    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

    提前感谢, 文斯。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Matphy    7 年前

    尝试:

    out_data.X[:, i] = newCumsumColValues
    

    i

    out_data.domain.index(out_data.domain['myCumsumcolTarget'])