Writing multi-indexed data to an excel file with Python/Pandas

Viewed 472

I want to create an Excel spreadsheet and insert equal number of rows for each of variable. The ideal result shall looked like Columns A & B in the picture.

What I can do so far is only to insert for 1 name (Columns D & E), and have no idea do the proper enumeration for the rest.

name and food

This is what I have:

import xlwt, xlrd
import os

current_file = xlwt.Workbook()
write_table = current_file.add_sheet('Sheet1')

name_list = ["Jack", "David", "Andy"]
food_list = ["Ice-cream", "Mango", "Apple", "Cake"]

total_rows = len(name_list) * len(food_list)   # how to use it?

write_table.write(0, 0, "Jack")

for row, food in enumerate(food_list):
    write_table.write(row, 1, food)

current_file.save("c:\\name_food.xls")

How can I do it for all? Thank you.

2 Answers
Related