Skip to content
Advertisement

If statement getting Skipped in a Function

I have defined a function that takes three entries, 2 numbers and an array. The Array is a 800 row 10 col array.

The first column in the array has a number for a state (target_province)

What I want the function to do is go row by row and assign the column data for each province to an empty array and return it.

However it looks like the if statement is getting skipped. Did i use the wrong syntax?

def get_Province_Data(target_province,data,array):
    Date=[]
    Data_Set=[]
    f=0
    for rows in array:
        province=array[f][0]
        
        if province == target_province:
            
            np.append(Date,array[f][data]) 
            np.append(Data_Set,array[f][3]) #gets the date data from  rom f column 3
            print(1)
            
        f=f+1
        
    return Date,Data_Set

alpha, cases=get_Province_Data(35,4,CSV_Array)

print(cases)
'''

Advertisement

Answer

the value read from files is String type by default. You are comparing lets say string ‘1’ and int 1.

use this instead

if int(province) == target_province:
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement