1
$\begingroup$

enter image description here

So have this table above. I'm trying to aggregate the occupations such that the table results in:

enter image description here

I've tried using df.groupby(['Occupation']) but I get an error. All I know is that my final step would be to set the index to "Occupation". But I still don't know how to group via entries in the single Occupation column here.

Also, what type of table would the final table be name/called?

I know it's not called a mutiindex table because there is only one index that the results are being grouped by.

$\endgroup$
1
  • 1
    $\begingroup$ It seems you're not applying any function to aggregate each group. $\endgroup$
    – tkarahan
    Apr 24 at 19:42
0
$\begingroup$

Your issue might occur if you didn't tell that the second row in the table should also be considered a header line.

To address this, try to reset the header at the beginning.

import pandas as pd

df = pd.read_csv('YOUR/FILE/DIRECOTRY.csv', skiprows=1) // ignore the 2nd row (0-indexed)
df.rename(columns={0:'Index'}, inplace=True) // optional
df.groupby(['Occupation'])
$\endgroup$
1
  • $\begingroup$ Thank you so much for the help! $\endgroup$
    – J. Doe
    Apr 26 at 4:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.