【发布时间】:2016-12-01 21:02:28
【问题描述】:
我有一个生成的列表列表如下:
input = ['a','b','c','d','e','f','g']
siglist = sum([map(list, combinations(input, i)) for i in range(len(input) + 1)], [])
print siglist[25]
['d', 'g']
现在,我想在现有数据框 df 中创建一个“新”列,如下所示
color location type new
blue TX MATTE [d,g]
black NA GLOSS [d,g]
red UT MATTE [d,g]
orange UT GLOSS [d,g]
white WA MATTE [d,g]
我希望像下面这样的东西会起作用;
df['new'] = (siglist[25])[:]
但是,我收到一个错误:ValueError: Length of values does not match length of index
任何人都可以帮忙,这里做错了什么。
【问题讨论】:
标签: list python-2.7 pandas