im trying to apply np.roll with groupy of pandas.
Actually, i have this dataframe: (In the columns complete_contracts_shift i applied shift with groupby:
df.groupby(['contracts ','param_contrct'])['complete_contracts '].shift(1)
| complete_contracts | contracts | param_contrct | complete_contracts_shift |
|---|---|---|---|
| F21-EZ-01/01/2022 | F21 | EZ | NaN |
| F21-EZ-02/01/2022 | F21 | EZ | F21-EZ-01/01/2022 |
| F21-EZ-03/01/2022 | F21 | EZ | F21-EZ-02/01/2022 |
| F21-AB-01/01/2022 | F21 | AB | NaN |
| F21-AB-02/01/2022 | F21 | AB | F21-AB-01/01/2022 |
| F21-AB-03/01/2022 | F21 | AB | F21-AB-02/01/2022 |
I need that dataframe has the column 'complete_contracts_shift' as follows:
| complete_contracts | contracts | param_contrct | complete_contracts_shift |
|---|---|---|---|
| F21-EZ-01/01/2022 | F21 | EZ | F21-EZ-03/01/2022 |
| F21-EZ-02/01/2022 | F21 | EZ | F21-EZ-01/01/2022 |
| F21-EZ-03/01/2022 | F21 | EZ | F21-EZ-02/01/2022 |
| F21-AB-01/01/2022 | F21 | AB | F21-AB-03/01/2022 |
| F21-AB-02/01/2022 | F21 | AB | F21-AB-01/01/2022 |
| F21-AB-03/01/2022 | F21 | AB | F21-AB-02/01/2022 |
i know np.roll of numpy, but i cant combinate this with groupby.