Given a Pandas DF like the one below were the key is "state county" I want to find all the zip codes that are associated with each key.
On a small scale I accomplished this using a loop but it is not efficient for the 50,000 keys I need to check. Is there a programing concept I can use to solve this without having to check each line against all the other lines?
Original df
state county | zip |
---|---|
VA Culpeper County | 20106 |
VA Fauquier County | 20115 |
VA Loudoun County | 20101 |
VA Loudoun County | 20102 |
VA Loudoun County | 20103 |
VA Loudoun County | 20104 |
VA Loudoun County | 20105 |
VA Loudoun County | 20107 |
VA Manassas City | 20108 |
VA Manassas city | 20110 |
VA Manassas City | 20113 |
VA Prince William County | 20109 |
VA Prince William County | 20111 |
VA Prince William County | 20112 |
Output df
state county | zip 1 | zip 2 | zip 3 | zip 4 | zip 5 | zip 6 | zip 7 | zip 8 | zip 9 | zip 10 |
---|---|---|---|---|---|---|---|---|---|---|
VA Culpeper County | 20106 | |||||||||
VA Fauquier County | 20115 | |||||||||
VA Loudoun County | 20101 | 20102 | 20103 | 20104 | 20105 | 20107 | ||||
VA Manassas City | 20108 | 20110 | 20113 | |||||||
VA Prince William County | 20109 | 20111 | 20112 |