私信  •  关注

IQbrod

IQbrod 最近创建的主题
IQbrod 最近回复了
7 年前
回复了 IQbrod 创建的主题 » python中是否有同时扩展数据帧行和列的方法?

这是一个 sample of code

def myFunction(base, plus):
    #Initialize result array
    result = []
    #For Each tuple in entry
    for bas in base:
        #Get Last Element
        lastElem = bas[-1:][0]
        #For Each element to add
        for x in plus:
            # Append a tuple composed of base + sum(lastElement & element to add)
            result.append(bas + ( (lastElem+x),) )
    # Return result
    return result

又回来了

first_elem = [(18,)]   
add = [6,0,-6]
print(myFunction(first_elem, [6,0,-6]))
#[(18, 24), (18, 18), (18, 12)]
print(myFunction([(18, 24), (18, 18), (18, 12)], [6,0,-6]))
#[(18, 24, 30), (18, 24, 24), (18, 24, 18), (18, 18, 24), (18, 18, 18), (18, 18, 12), (18, 12, 18), (18, 12, 12), (18, 12, 6)]