| Index | E_Id | P_Id | Date |
|---|---|---|---|
| 121 | 701 | 9002 | 2021 |
| 122 | 701 | 9001 | 2019 |
| 123 | 702 | 9002 | 2021 |
| 124 | 702 | 9002 | 2019 |
| 125 | 703 | 9001 | 2021 |
| 126 | 704 | 9002 | 2019 |
| 127 | 704 | 9003 | 2019 |
Now I want to Create another DataFrame groupedby E_Id But I want to Count the number of rows against each P_Id call it 'x', and then sum of 'x' for whoever is linked with each E_Id
So
| E_Id | TotalOfPIds |
|---|---|
| 701 | 6 |
Can anyone help me?
As an intermediary step, I did this:
data['_Pid_Total'] = data.groupby('P_Id')[['P_Id']].transform('count')
And then for single E_Id it works like this:
data.loc[data['E_Id'] == '701', ['E_Id', 'P_Id', '_Pid_Total']].groupby(['E_Id', 'P_Id']).first().sum() returning a single integer. However I want to use this in Transform method or just do it for entire DataFrame.