Sep-18-2018, 03:45 PM
I'm trying to load and read through an excel file and based on the value of a cell write the row to another file.
Problem I'm having now is that row[1].value is a string and I need to convert it to a number so that I can apply a great than > condition
The code I have so far which works based on the == is this:
TypeError: '>' not supported between instances of 'str' and 'int'
Any ideas?
Problem I'm having now is that row[1].value is a string and I need to convert it to a number so that I can apply a great than > condition
The code I have so far which works based on the == is this:
# Import `load_workbook` module from `openpyxl`
from openpyxl import load_workbook
# Load in the workbook
wb = load_workbook('myFile.xlsx')
#activate a sheet into array
sheet = wb['Sheet1']
# select all populated rows and iterate through
for row in sheet.iter_rows(min_col=1, min_row=1, max_col=2, max_row=sheet.max_row):
if row[1].value == 1:
pass
else:
print(row[0].value)If I change the condition in within the loop to a "greater than" like this:# Import `load_workbook` module from `openpyxl`
from openpyxl import load_workbook
# Load in the workbook
wb = load_workbook('myFile.xlsx')
#activate a sheet into array
sheet = wb['Sheet1']
# select all populated rows and iterate through
for row in sheet.iter_rows(min_col=1, min_row=1, max_col=2, max_row=sheet.max_row):
if row[1].value == 1:
pass
else:
print(row[0].value)Then I get the error:TypeError: '>' not supported between instances of 'str' and 'int'
Any ideas?
