社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

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)]