tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

Our data will not merge #47

Open cahicks opened 6 years ago

cahicks commented 6 years ago

What I think has happened, is that python does not see that our 2 data sets have a common variable. our code looks like this

# initialize data to empty list
merged_data = []

# go through every line in data
for line in f_data:
    if line[0] not in f2_data:
        print "Key not in f2_data:",line
    else:
        merged_data.append(line + f2_data[line[0]])

print merged_data

When we print the merged_data, we get back an empty list. However, we have printed the headers for both of our data sets and you can see that they both have the variable 'State' in common: f_data: ['Rank', 'Player', 'Team', 'Position', 'Games', 'At Bats', 'Runs', 'Hits', 'Doubles', 'Triples', 'Homeruns', 'RBI', 'Walks', 'Strikeouts', 'Stolen Bases', 'Batting Avg', 'On Base Pct', 'Slugging Pct', 'State'] f2_data: ['State', 'CENSUS2010POP'] How do we get python to recognize that we have a common variable?