Reputation: 25
I have a pandas dataframe (players) with headers (passes, tackles....)
I am looking to get a correlation coefficient for a few of the columns (not all)
for stats in [passes,tackles,shots,saves]:
cc = np.corrcoef(players.minutes, players.stats)[1,0]
print cc
However, my code returns
name 'passes' is not defined
because passes is not a defined variable. Is there an easy way to iterate over certain columns for this type of analysis?
Upvotes: 1
Views: 160
Reputation: 1540
for stats in ['passes','tackles','shots','saves']:
cc = np.corrcoef(players['minutes'], players[stats])[1,0]
print cc
Upvotes: 3