2
votes

Forgive the basic question, but I can't find the answer anywhere. I'm trying to import values from an Excel column using xlrd and turn them into a list. Any suggestions? Here's what I have so far, but the list returns all values with "number: 1.0" instead of just 1.0.

# Access Excel Workbook
datafile = "Household Debt Values.xlsx"
workbook = xlrd.open_workbook(datafile)
sheet = workbook.sheet_by_index(0)

# Create CBSA list 
CBSAlist = []
for value in sheet.col(1):
   CBSAlist.append(value)
print CBSAlist

Returns: [number:1.0, number:2.0, number:3.0, number:4.0, number:5.0, number:6.0, number:7.0, number:8.0, number:9.0, number:10.0, number:11.0, number:12.0, number:13.0, number:14.0, number:15.0, number:16.0, number:17.0, number:18.0, number:19.0, number:20.0, number:21.0, number:22.0, number:23.0, number:24.0, number:25.0]

1

1 Answers

1
votes

Try split the value first:

# Create CBSA list 
CBSAlist = []
for value in sheet.col(1):
    CBSAlist.append(float(str(value).split(":")[1]))
print CBSAlist

Result

[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]