I have the following dataframe:
p_id c_id region account state
A0001 100 east CA1000 VA
A0001 100 east CA1001 GA
A0001 100 west CA1002 CA
A0001 101 west CA1004 TX
A0001 101 west CA1007 GA
A0002 108 east CA1013 MI
A0002 109 east CA1018 WA
A0002 109 east CA1020 AZ
I want to store each unique account & state in separate columns for the same p_id + c_id + region. So the output looks like:
p_id c_id region account_1 state_1 account_2 state_2 account_3 state_3 account_4 state_4
A0001 100 east CA1000 VA CA1001 GA
A0001 100 west CA1002 CA
A0001 101 west CA1004 TX CA1007 GA
A0002 108 east CA1013 MI
A0002 109 east CA1018 WA CA1020 AZ
Note:
- I need 8 additional columns in the output (account_1 ~ 4 and state_1 ~ 4), even if there is less than 4 different account & state from every combination of p_id, c_id and region in the whole dataframe.
- Keep values blank in new columns if there is no values.