The problem is on this line:
if fifa['short_name'][x]=='Nunez':
fifa['short_name']
is a Series;
fifa['short_name'][x]
tries to index that series with x
;
- your code doesn't show it, but the stack trace suggests
x
is some scalar type;
pandas
tries to look up x
in the index of fifa['short_name']
, and it's not there, resulting in the error.
Since the Series will share the index of the dataframe fifa
, this means that the index x
isn't in the dataframe. And it probably isn't, because you let x
range from 0
upto (but not including) len(fifa)
.
What is the index of your dataframe? You didn't include the definition of params
, nor that of fifa
, but your problem is most likely in the latter, or you should loop over the dataframe differently, by looping over its index instead of just integers.
However, there's more efficient ways to do what you're trying to do generally in pandas
- you should just include some definition of the dataframe to allow people to show you the correct one.