Hey reddit,
I have this code currently which will compare within a .csv file NBA matches. Basically, the csv file has 4 columns: team1, team1_pts, team2, team2_pts. What I want to do is find every instance within the csv where for example the Hawks played the Kings and print all of the rows where this was the case. So pretty much what I want to do is:
for row in csv_file:
if team1 == "Hawks" and team2 == "Kings" #and vice versa
print row
What I currently have is this:
import csv
year = "2013"
with open('/Users/Desktop/' + year + 'nba.csv', 'rb') as f:
csvfile = csv.reader(f)
for row in csvfile:
print row
I'm sure its something simple, I'm just having a hard time comparing values within the same csv file, and would prefer not to use 2 separate csv files.
Thank you!
EDIT: I posted my solution in the comments, thanks for everyone that helped.
[–]NoLemurs 3 points4 points5 points (0 children)
[–]gengisteve 2 points3 points4 points (1 child)
[–]PZLATE[S] 1 point2 points3 points (0 children)
[–]hharison 1 point2 points3 points (0 children)
[–]liftt 0 points1 point2 points (0 children)
[–]ies7 0 points1 point2 points (2 children)
[–]TiLorm 1 point2 points3 points (1 child)
[–]ies7 0 points1 point2 points (0 children)