1

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.

desertnaut
  • 1,908
  • 2
  • 13
  • 23
J. Doe
  • 13
  • 2

1 Answers1

0

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'])