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?
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
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?