title: Pandas groupby is giving "keyError", even when the key exists
body: <p>I am new to Python, and for one of my project, I need to convert csv to nested Json. Searching on net, I found <code>pandas</code> are helpful in this case.
  I followed the appraoch given in <a href="https://stackoverflow.com/questions/51095528/convert-csv-data-to-nested-json-in-python">Convert CSV Data to Nested JSON in Python</a> 
  But I am getting a keyError exception <code>KeyError: 'state'</code></p>
  
  <pre><code>df info
  &lt;class 'pandas.core.frame.DataFrame'&gt;
  RangeIndex: 4 entries, 0 to 3
  Data columns (total 3 columns):
  country    4 non-null object
   state     4 non-null object
   city      4 non-null object
  dtypes: object(3)
  memory usage: 176.0+ bytes
  None
  Traceback (most recent call last):
    File "csvToJson.py", line 31, in &lt;module&gt;
      grouped = df.groupby(['country', 'state'])
    File "/home/simarpreet/Envs/j/lib/python3.7/site-packages/pandas/core/generic.py", line 7632, in groupby
      observed=observed, **kwargs)
    File "/home/simarpreet/Envs/j/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 2110, in groupby
      return klass(obj, by, **kwds)
    File "/home/simarpreet/Envs/j/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 360, in __init__
      mutated=self.mutated)
    File "/home/simarpreet/Envs/j/lib/python3.7/site-packages/pandas/core/groupby/grouper.py", line 578, in _get_grouper
      raise KeyError(gpr)
  KeyError: 'state'
  
  </code></pre>
  
  <p>Input csv:</p>
  
  <pre><code>country, state, city
  India, Delhi, Tilak nagar
  India, Mumbai, Bandra
  Australia, Queensland, Gold Coast
  US, California, Los Angeles
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>csvFilePath = "/home/simarpreet/sampleCsv.csv"
  jsonFilePath = "/home/simarpreet/sampleJson.json"
  jsonFile = open(jsonFilePath, 'w')
  
  df = pd.read_csv(csvFilePath, encoding='utf-8-sig')
  print("df info")
  print(df.info())
  finalList = []
  
  grouped = df.groupby(['country', 'state'])
  for key, value in grouped:
      dictionary = {}
  
      j = grouped.get_group(key).reset_index(drop=True)
      dictionary['country'] = j.at[0, 'country']
      dictionary['state'] = j.at[0, 'state']
  
      dictList = []
      anotherDict = {}
      for i in j.index:
  
          anotherDict['city'] = j.at[i, 'city']
  
          dictList.append(anotherDict)
  
      dictionary['children'] = dictList
  
      finalList.append(dictionary)
  
  json.dumps(finalList)
  
  </code></pre>