Rename several unnamed columns in a pandas dataframe
<p>I imported a csv as a dataframe from San Francisco Salaries database from Kaggle</p>

<pre><code>df=pd.read_csv('Salaries.csv')
</code></pre>

<p>I created a dataframe as an aggregate function from 'df'</p>

<pre><code>df2=df.groupby(['JobTitle','Year'])[['TotalPay']].median()
</code></pre>

<p>Problem 1: The first and second column appear as nameless and that shouldn't happen.</p>

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

<p>Even when I use code of</p>

<pre><code>df2.columns
</code></pre>

<p>It only names TotalPay as a column</p>

<p>Problem 2: I try to rename, for instance, the first column as JobTitle and the code doesn't do anything</p>

<pre><code>df3=df2.rename(columns = {0:'JobTitle'},inplace=True)
</code></pre>

<p>So the solution that was given here does not apparently work: <a href="http://stackoverflow.com/questions/26098710/rename-unnamed-column-pandas-dataframe">Rename unnamed column pandas dataframe</a>.</p>

<p>I wish two possible solutions:
1) That the aggregate function respects the column naming AND/OR
2) Rename the empty dataframe's columns</p>

<p>The problem isn't really that you need to rename the columns.<br>
What do the first few rows of the .csv file that you're importing look at, because you're not importing it properly. Pandas isn't recognising that <code>JobTitle</code> and <code>Year</code> are meant to be column headers. Pandas <code>read_csv()</code> is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">very flexible</a> with what it will let you do.<br>
If you import the data properly, you won't need to reindex, or relabel. </p>

python pandas dataframe aggregate-functions series