title: How can I count occurrences of a string in a csv file row if another row has a certain value?
body: <p>I have a csv file with one row of country values and one row of Olympic medals. iI want to count which country got how many medals.</p>
  
  <p>I tried it with pandas but it gives me the error message that it cannot find the row "country", although the row does exist and it is named country
  The CSV file:</p>
  
  <p><a href="https://i.stack.imgur.com/8rsfZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8rsfZ.png" alt="screenshot of CSV file contents"></a></p>
  
  <pre class="lang-py prettyprint-override"><code>from collections import Counter
  import pandas as pd
  import csv
  
  with open('olympics.csv', 'r', encoding='utf-8', newline='') as csv_file:
  
      df = pd.read_csv("olympics.csv",
                       index_col=["NOC","Medal"])
                       #usecols=["NOC","Medal"])
      #df.sort_index()
  
      #grouped = df.groupby(['NOC', 'Medal'])
  
      grouped = df.groupby(['NOC','Medal'])['NOC'].count()
  
  print(grouped)
  </code></pre>
  
  <p>The output should be like:</p>
  
  <pre class="lang-none prettyprint-override"><code>USA 2366 
  UK  2189 
  Denmark 1455 
  ....
  </code></pre>