I have a problem with exploding a DataFrame down into separate rows against a comma delimited list after splitting across to a set amount of cols. I'm trying to achieve this in Pandas but if this is possible using raw SQL (I tried and gave up) then that would be an ideal solution.
Sample Data
Reference Surname Forename CurrentPostCode PreviousPostCodes
1 Smith John WA1 2LA WA2 HG5, LN4 6XS
2 Jones Jack NA1 2NE None
3 Potter Harry LI8 0NX None
4 Wane Bruce HE27 4PR HE5 9PR
5 Finn Grahame B26 7UP B15 6UR, B22 9JK, B13 3YT
The I want to split the PreviousPostCodes column across into two columns PPC1 and PPC2 and if the array/comma separated list has more than 2 items in it (in the case of Ref 5) it would need to split the first two and the add a row below and fill PPC1 with B13 3YT
Desired Output
Reference Surname Forename CurrentPostCode PPC1 PPC2
1 Smith John WA1 2LA WA2 HG5 LN4 6XS
2 Jones Jack NA1 2NE None None
3 Potter Harry LI8 0NX None None
4 Wane Bruce HE27 4PR HE5 9PR None
5 Finn Grahame B26 7UP B15 6UR B22 9JK
5 Finn Grahame B26 7UP B13 3YT None
I hope this makes sense, I can split the list out but i get n cols and i want to limit that to a maximum size of 2, and overflow onto new rows if it exceeds 2. There isn't a limit to the amount of previous postcodes in the data so if there were 5 in the comma separated list, it would need to explode the row down into 3 new rows.
Thanks