By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

How to input data from an excel file into a list

P: 4
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),...])
Jan 17 '14 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Here's an example:
Expand|Select|Wrap|Line Numbers
  1. import xlrd
  2. from PIL import Image
  3.  
  4. height = 100
  5.  
  6. wb = xlrd.open_workbook("rgb_values.xlsx")
  7. sheet1 = wb.sheet_by_index(0)
  8. data = []
  9. for i in range(0, sheet1.nrows):
  10.     for line in range(height):
  11.         data.append(tuple(int(j) for j in sheet1.row_values(i)))
  12.  
  13. im = Image.new("RGB", (sheet1.nrows, height))
  14. im.putdata(data)
  15. im.save("pix1.png")
Jan 17 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.