简体   繁体   English

如果语句在函数中被跳过

[英]If statement getting Skipped in a Function

I have defined a function that takes three entries, 2 numbers and an array.我已经定义了一个函数,它需要三个条目、2 个数字和一个数组。 The Array is a 800 row 10 col array.该阵列是一个 800 行 10 列的阵列。

The first column in the array has a number for a state (target_province)数组中的第一列有一个州的编号(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.但是,似乎 if 语句被跳过了。 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)
'''

the value read from files is String type by default.从文件中读取的值默认为 String 类型。 You are comparing lets say string '1' and int 1.您正在比较让我们说字符串 '1' 和 int 1。

use this instead改用这个

if int(province) == target_province:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM