I am trying to calculate the mean, mode and median for 2 columns in a dataframe. I want to groupby COL1 and calculate the mean, mode and median for COL2. There are numerous columns and rows but an example of the 2 I wish to use are shown below below
COL1 COL2
1 (0-9) 64
2 (10-19) 74
3 (20-29) 64
4 (0-9) 62
I have been trying code as below but continually get errors:
data.groupby('COL1')['COL2'].mean()
If I do a groupby with just COL1 this returns the mean (and median but not mode) for 2 other columns fine but not COL2:
data1 = data.groupby(['COL1']).mean()
I think there may be an issue with COL2 showing as an object but I am having difficulty in fixing this. An example error is shown below:
pandas.core.base.DataError: No numeric types to aggregate