How to input data from an excel file into a list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bhag
    New Member
    • Jan 2014
    • 4

    How to input data from an excel file into a list

    Hi,

    I have an excel file which contains 3 columns and lots of rows. How do I put these data into a list in Python? (like [(1,2,3),(4,5,6) ,...])
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Here's an example:
    Code:
    import xlrd
    from PIL import Image
    
    height = 100
    
    wb = xlrd.open_workbook("rgb_values.xlsx")
    sheet1 = wb.sheet_by_index(0)
    data = []
    for i in range(0, sheet1.nrows):
        for line in range(height):
            data.append(tuple(int(j) for j in sheet1.row_values(i)))
    
    im = Image.new("RGB", (sheet1.nrows, height))
    im.putdata(data)
    im.save("pix1.png")

    Comment

    Working...