Column index 'x' out of range

I am running a script looking at a dataset,
The code in question is this…

if labelName == ‘DEFECT LABEL 3’:
return pyData[0][0]
if labelName == ‘DEFECT LABEL 4’:
return pyData[1][0]
if labelName == ‘DEFECT LABEL 5’:
return pyData[2][0]

it works great, but sometimes my data set won’t have as many rows as I have if statements.
How can I say -
if pyData[1][0] is out of range:
return ‘NA’
return pyData[1][0]

Thank you…

you could check the length of your dataset first. then in each if statement, first check to make sure that the row you are asking for is within the range of the dataset.

Awesome, works perfect. Thank you!