I was wondering if there is a kind of "when statement" in Python. For instance, in the code below, at some point all of the observations are true. The way I wrote it, only reads the first statement and ignores the other 2. How can I make it work to print the counts of all the observations under that particular condition?
counts_zero_time = 0
counts_zero_time_non_zero_dist = 0
counts_zero_time_zero_dist = 0
for index,row in df.iterrows():
if row["time_interval"] == 0:
counts_zero_time += 1
elif row["time_interval"] == 0 and row["distance"] !=0:
counts_zero_time_non_zero_dist += 1
elif row["time_interval"] == 0 and row["distance"] ==0:
counts_zero_time_zero_dist += 1
print(counts_zero_time, "observations have a time interval of 0")
print(counts_zero_time_non_zero_dist, "observations have a time interval of 0 and a non-zero distance")
print(counts_zero_time_zero_dist, "observations have a time interval and distance of 0")
In the output, I get the correct counts for the first condition but I get zero for the other two which is incorrect.
1421 observations have a time interval of 0
0 observations have a time interval of 0 and a non-zero distance
0 observations have a time interval and distance of 0