我有两个列表列表,如下所示
ingre_list = [['chicken',
'oil',
'garlic',
'pepper',
'juice',
'sugar',
'ketchup',
'vinegar',
'water',
'sauce'],
['butter', 'sugar', 'eggs', 'bananas', 'salt'],
['pork',
'beef',
'egg',
'cheese',
'bread',
'garlic',
'salt',
'pepper',
'milk',
'parsley'],
['beef',
'bread',
'egg',
'onions',
'salt',
'pepper',
'ketchup',
'milk',
'vinegar',
'sugar',
'ketchup'],
['salt', 'sugar', 'butter'],
['sausage',
'garlic',
'tomatoes',
'sauce',
'water',
'basil',
'parsley',
'sugar',
'salt',
'pepper',
'pepper',
'spaghetti',
'cheese'],
['bananas',
'juice',
'salt',
'butter',
'sugar',
'eggs',
'butter',
'cheese',
'cream',
'sugar'],
['beef', 'gravy', 'dressing', 'dressing', 'water'],
['salt', 'butter', 'sugar', 'sugar', 'eggs', 'oats', 'raisins']]
quan_list= [['2 lbs',
'2',
'2',
'3/4 teaspoon',
'1/4 cup',
'1/3 cup',
'2 tablespoons',
'1 tablespoon',
'1/2 cup',
'1/3 cup'],
['1/2 cup', '1 cup', '1', '1', '1/2 teaspoon'],
['1/2',
'1/2',
'1/2',
'1/2 cup',
'1/3 cup',
'1/3',
'1/3',
'1 teaspoon',
'1/3 cup',
'1/4 cup'],
['1/4',
'1/4',
'1/4',
'1/4',
'1 teaspoon',
'1/4 teaspoon',
'4 tablespoons',
'1/2-2/3 cup',
'4 tablespoons',
'4',
'1/2 cup'],
['1 teaspoon', '1/4 cup', '1/2 cup'],
['2 lbs',
'2',
'2',
'2',
'2 cups',
'3 teaspoons',
'2 teaspoons',
'2',
和 的长度相同。两个列表的每个内部列表的长度相同。例如,具有 与 相同的大小。我想从这些列表中创建一个数据帧,其中标题是 来自 的项目,每个项目都应该在标题中出现一次。然后,每行应包含 来自 的成分的数量。为了创建空数据帧,我使用了以下代码:quan_listingre_listquan_list[0]ingre_list[0]ingre_listquan_list
unique_ingre= set(x for l in ingre_list for x in l)
df1 = pd.DataFrame(columns=unique_ingre)
现在我很难在每行中插入数量。
示例数据帧考虑值和ingre_list[0]quan_list[0]
bread egg chicken sugar dressing ..... water garlic
2 lbs 1/3 cup 1/2 cup 2
如果有人能帮助我,它真的非常感谢。只是为了让你知道quan_list和ingre_list的长度可能会增加。如果这个东西可以写在python的csv文件中,那也很好。
largeQ
相关分类