Q:

pandas pivot table giving me aggregation error

Have a dataframe that looks like this:
      Unique_ID    Due_Date                     Provider
0           731   3/05/2019         Optus Mobile Pty Ltd
1           733   3/05/2019         Optus Mobile Pty Ltd
2           747  23/04/2019         Optus Mobile Pty Ltd
3           747  21/04/2019         Optus Mobile Pty Ltd
4           747  17/04/2019         Optus Mobile Pty Ltd

I'd like to perform a pivot_table to achieve the following:
      Unique_ID    Due_Date_1                   Provider_1    Due_Date_2  Provider_2              Due_Date_3  Provider_3
0           731    3/05/2019          Optus Mobile Pty Ltd
1           733    3/05/2019          Optus Mobile Pty Ltd
2           747    23/04/2019         Optus Mobile Pty Ltd    21/04/2019  Optus Mobile Pty Ltd    17/04/2019  Optus Mobile Pty Ltd

I am trying somethinng like the following:
df.pivot_table(index=['Unique_ID'], columns='Due_Date', values='Provider')
but I am getting returned a bunch of errors.
pandas.core.base.DataError: No numeric types to aggregate
Note, this is a snippet of a much larger dataset, and there will be many Unique_ID to perform on. 

Do I need to perform a groupby first?

A:

df['key']=(df.groupby('Unique_ID').cumcount()+1).astype(str)
s=df.pivot_table(index='Unique_ID',columns='key',values=['Due_Date','Provider'],aggfunc='first').sort_index(level=1,axis=1)
s.columns=s.columns.map('_'.join)
s
Out[54]: 
           Due_Date_1 Provider_1  Due_Date_2 Provider_2  Due_Date_3 Provider_3
Unique_ID                                                                     
731         3/05/2019      Optus         NaN        NaN         NaN        NaN
733         3/05/2019      Optus         NaN        NaN         NaN        NaN
747        23/04/2019      Optus  21/04/2019      Optus  17/04/2019      Optus

