Creating Dataframe from csv with pandas
<p>I have a csv file with the following layout: year, race, sex, age and population. Each year has several different groups. </p>

<p>I created the following Dataframe from the CSV</p>

<pre><code>CSV_df = pd.read_csv('Data/Demographics/Demo/akwbo19ages.csv') 

df = CSV_df[CSV_df["age"] &gt;= 4].groupby(["year","race","sex","age"])['pop'].sum()
</code></pre>

<p>which results in </p>

<pre><code>year  race  sex  age
1969  1     1    1      10574
                 2      20245
                 ...
                 n      11715
            2    1       8924
                 2       9919
                 ...
                 n       9960
                        ...  
2012  3     1    1       7861
                 2       8242
                 ...
                 n       7268
            2    1       7245
                 2       7821
                 ...
                 n       6912
</code></pre>

<p>However, what I would like to have is for each row to represent a single year and have several columns representing each group (i.e. columns with population figures for each possible combination of race, sex and age group)</p>

<pre><code>year  group1  group2 ... groupN
1969  10574   20245      9960
...
2012  7861    8242       6912
</code></pre>