Python Forum

Full Version: Problem with If statement and dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to use an If statement with a Dataframe. Without the If statement the Dataframe prints out beautifully, But it prints out all 63 rows. I am trying to check if field in Dataframe matched user input. Can someone tell me what I am doing wrong?

def load_track_to_Handi():
	my_tracklabel= Label(root, text ="                                                                               ", fg= "#F50808", font = ("sans_serif" , 16)).place(x=380, y=430)
	read_csvfile_into_array()
	
		
	global track_abrev
	global race_number
	global xx
	
	#if fileFound ==True:

		
		 
	
	
	hcount = 0
	
	with open( 'C://guis/f_racefiles/'+ track_abrev + '.csv' , 'r') as race_file:

		
		df = pd.read_csv(race_file, header =None)
		
		xx = df.iloc[ :,0:19 ].values
		
		

		for i in range(0,len(xx)):
			if (xx[hcount][1] == race_number):
				print(xx)[hcount][18])					
				hcount+=1	                          				       		
I remove if statement and prints out with no problem. Race number is an integer and I believe the field in the dataframe is an interger also, as it is a race number.
This is the printout I get when I remove the if statement. I am trying to match user input (racenumber0 with the 2nd column in the dataframe, with the code in above post.

[['AP ' 1 'D' ... 42 3.0 'EYE ON THE FINISH']
['AP ' 1 'D' ... 46 10.0 'GODSGIFT']
['AP ' 1 'D' ... 82 8.0 'LILLET']
...
['AP ' 8 'D' ... 35 6.0 'WILDCAT LITE']
['AP ' 8 'D' ... 46 15.0 'GREELEYS ICE']
['AP ' 8 'D' ... 29 12.0 'JIVE DADDY']]

This was the code I changed and it worked. I am amazed...LOl.
for i in range(0,len(xx)):
			if int(xx[hcount][1])== int(race_number):
			 
				print(xx[hcount][18])					
				hcount+=1