我有一个while循环,它从一个列表中随机返回三个项目。然后再次执行相同操作,直到列表为空。我想在一个数据帧中收集所有这16行
from random import randint
colors = ['Pink', 'Purple', 'Green', 'Skyblue', 'Blue', 'Grey'] * 8
while colors:
lst = [colors.pop(randint(0, len(colors) - 1)) for _ in range(3)]
print(lst)
我的目标是从while循环返回一个包含四列和16行的pandas数据帧
pd.DataFrame(index=np.arange(1,17), columns = ["Store", "Bar 1", "Bar 2", "Bar 3"])
我似乎不知道如何获得while循环来返回这样的数据帧。任何帮助都将不胜感激
有几件事你在问题中没有具体说明,比如:
while
循环李>dataframe
添加另一个没有值的列(讨论该store
列)李>将第一列视为“是”,第二列视为“第一列将是另一个值,您将在代码中添加一些修改”,选项如下:
执行它以获得:
相关问题 更多 >
编程相关推荐