Deuce525 Deuce525 - 1 year ago 91
Python Question

For Loop for excel data table in python


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:
print FirstList

Answer Source

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:
print FirstList
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download