【发布时间】:2019-05-14 18:17:11
【问题描述】:
我正在尝试将我生成的组合相乘并从中创建一个新列表。
这是我目前所拥有的:
import pandas as pd
import itertools
data1 = [[0.1],[0.2],[0.3],[0.5]]
df = pd.DataFrame(data1, columns = ['weights'])
for x in combinations(df['weights'], 2):
print(x)
>>>
(0.1, 0.2)
(0.1, 0.3)
(0.1, 0.5)
(0.2, 0.3)
(0.2, 0.5)
(0.3, 0.5)
##I want to make a new list that shows the product of each combinations,
## example: for every (x,y) combo, do x*y and make a new list called z
预期的输出应该产生一个新的列表:
0.02
0.03
0.05
0.06
0.1
0.15
【问题讨论】:
-
欢迎来到 Stack Overflow!您正在寻找如何map。这是另一个有帮助的问题:stackoverflow.com/a/19017344/350538
标签: python combinations itertools multiplication