社区所有版块导航
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
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何从列表中包含数据帧的Python列表元素生成所有可能的组合?

rsx • 3 年前 • 1819 次点击  

下午好 我有一个Python列表。例子:

mylist = [['a', 'b', 'c'],
          [1, 2],
          [df1, df2]]

df1, df2 是数据帧。我想产生类似于 itertools.product(*mylist) .

问题是熊猫数据帧本身是可编辑的,因此 product 回报不是我想要的。我想要:

[('a', 1, df1),
 ('a', 1, df2),
 ('a', 2, df1),
 ('a', 2, df2),
 ('b', 1, df1),
 ('b', 1, df2),
 ('b', 2, df1),
 ('b', 2, df2),
 ('c', 1, df1),
 ('c', 1, df2),
 ('c', 2, df1),
 ('c', 2, df2)]

但是 产品 当然,无法生成所需的ouptut,因为它开始迭代 df1 df2 柱。我怎样才能以优雅的方式解决这个问题?

感谢您的帮助

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130164
 
1819 次点击  
文章 [ 1 ]  |  最新文章 3 年前