VicentVega
VicentVega

Reputation: 191

Python - Looping through specific column in CSV file

I currently have my csv file displaying on python:

df = pd.read_csv("Desktop\Assignment\World Cup 2018.csv")
df.head()

Here I can see that my data has been opened and the unneeded columns have been removed. Now I want to use some variables named CounterVal1 (and so on) to count the amount of times a formation appears in a row.

for i in enumerate(df['home_formation']):
if i == '4-2-3-1':
    counterVal1 += 1
elif i == '4-1-4-1':
      counterVal2 += 1

performance = [counterVal1,counterVal2,counterVal3,counterVal4,counterVal5,counterVal6]

plt.bar(y_pos, performance, align='center', alpha=0.8)

However I have printed off one of these values and it appears that the data is not being searched through as show above.

My question: How do I take in the data from the CSV file, take just the column related to the formation and loop through it?

Upvotes: 0

Views: 236

Answers (1)

Omkar Sabade
Omkar Sabade

Reputation: 783

You haven't really provided much here. So this is just guess work.

Based on your comment I'm guessing this is what you want :

df['home-formation'].value_counts().plot('bar')

Upvotes: 2

Related Questions