Why does `set_index` create an index label for the column name?
<p>I have a CSV file which begins like this:</p>

<pre><code>Year,Boys,Girls
1996,333490,315995
1997,329577,313518
1998,325903,309998
</code></pre>

<p>When I read it into pandas and set an index, it isn't doing quite what I expect:</p>

<pre><code>df = pd.read_csv('../data/myfile.csv')
df.set_index('Year', inplace=True)
df.head()
</code></pre>

<p>Why is there an index entry for the column label, with blank values next to it? Shouldn't this simply disappear?</p>

<p><a href="http://i.stack.imgur.com/6pkxa.png" rel="nofollow"><img src="http://i.stack.imgur.com/6pkxa.png" alt="enter image description here"></a></p>

<p>Also, I'm not clear on how to retrieve the values for 1998. If I try <code>df.loc['1998']</code> I get an error: <code>KeyError: 'the label [1998] is not in the [index]'</code>.</p>

<p>You should set the name attribute of your index to <code>None</code>:</p>

<pre><code>df.index.names = [None]
df.head()
#       Boys    Girls
#1996   333490  315995
#1997   329577  313518
#1998   325903  309998
</code></pre>

<p>As for retrieving the data for <code>1998</code>, simply lose the quotes:</p>

<pre><code>df.loc[1998]
#Boys     325903
#Girls    309998
#Name: 1998, dtype: int64
</code></pre>

python pandas