0

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?

3
  • 1
    If I understand correctly, you can use performance = df['home_formation'].value_counts() to count every unique formation and not to iterate through 'home_formation' column. Or do you need to consider only certain formations? Commented Dec 17, 2018 at 15:04
  • I will be counting how many times all formations appear in the csv file and then displaying that in a bar chart Commented Dec 17, 2018 at 15:07
  • Possible duplicate of count the frequency that a value occurs in a dataframe column Commented Dec 17, 2018 at 15:10

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.