Deuce525 Deuce525 - 3 months ago 10
Python Question

For Loop for excel data table in python

All,

I have a csv file that lists stocks and their data. Column J in the Csv file shows their volume. I am trying to use the below code to sort the data into a list with stocks that have a volume higher than 1,000,000. However, when it prints the FirstList, it shows all stocks, including ones under the 1,000,000 rule. Any ideas why? Do I need to add Int or Float in my function?

FirstList = []
for i in range(5, 2000, 1):
FirstList.append(int(sheet.cell(row=i, column=9).value))
if (sheet.cell(row=i, column=9).value) > 1000000:
FirstList.append(i)
print FirstList

Answer

This what you're going for?

FirstList = []
for i in range(5, 2000, 1):
    value = int(sheet.cell(row=i, column=9).value)
    if value > 1000000:
        FirstList.append(value)
print FirstList