Ryker Ryker - 1 year ago 69
Python Question

How would I take an excel file and convert its columns into lists in Python?

I had the following question. Namely, suppose I have an excel file with some names in the first row. Then the next however many rows are single letter entries (so "A", "B", "C" and so on).

My goal is to extract the column and make it into a list, so that, say, for column 1 the list would start in row 2, the next entry would be from row 3, and so on, until the end is reached.

How would I do that in Python?

Answer Source

I figured out the answer. Assuming the Excel file is Test.xlsx, we can translate the j-th column (excluding the first row) into list_j as follows:

book = xlrd.open_workbook("Test.xlsx")
sheet = book.sheet_by_index(0)

list_j = []

for k in range(1,sheet.nrows):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download