I'm using this repository:
https://github.com/fivethirtyeight/data/blob/master/avengers/avengers.csv
For an exercise in DataQuest, I have to count the number of 'Years since joining' is correct by subtracting 2015 (reference year) from column 'Year'.
I'm trying to use a for and if loop to do this simple task but I am having a hard time figuring out. How do I incorporate the 'for row' into the loop?
def Years_joined():
joined_accuracy_count = 0
for row in avengers['Years since joining']:
if (2015 - avengers['Year']) == avengers['Years since joining']:
joined_accuracy_count += 1
return joined_accuracy_count
EDIT: Sorry for not giving more information. The file is in pandas. So pd.read_csv('avengers')
I have two columns. 'Year' and 'Years since joining'. For example, Year would be 1963. Years since joining would be 52. I am trying to write a for-if loop to see if 2015 - 1963 = 52. And if so, add that to a count.
Error: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
rowin the loop. See the first example here: wiki.python.org/moin/ForLoopDictReader()?pandas?avengers['Years since joining']is just an array of years, thenrowrepresents the current selected year for each loop iteration. So you'd just haveif (2015 - row) == ....