My original data has some column data that I'm expanding to their own columns. Here's how it starts:
Order ID Items Order Line item Properties 1 Title Order Line item Properties 1 Value
-------- ----- ---------------------------------- ----------------------------------
1 x Org ID 1234
2 x Org ID 5678
2 x Ship From DEN
2 y Ship To CLE
2 y Org ID 5678
2 y Ship From DEN
2 y Ship To CLE
I have some code that creates columns for Org ID, Ship From, and Ship To. The resulting data looks like this:
Order ID Items Org ID Ship From Ship To
-------- ----- ------ --------- --------
1 x 1234 None None
2 x 5678 None None
2 x 5678 DEN None
2 x 5678 None CLE
2 y 5678 None None
2 y 5678 DEN None
2 y 5678 None CLE
I'm trying to get the data to look like this:
Order ID Items Org ID Ship From Ship To
-------- ----- ------ --------- --------
1 x 1234 None None
2 x, y 5678 DEN CLE
I think I have a grasp on everything except concatenating the items to show up as x, y when the rest of the data is the same.
Here is some of the code that gets me almost all of the way there:
df.groupby('Order ID').apply(lambda x: x.ffill().bfill()).drop_duplicates()
I can get to the string I want with this: [str(x) for x in df['Items']], but I'm not sure how to get that into the items field for the resulting row(s).
What can I do to merge, concatenate, squash, join, or whatever the correct word is to end up with x, y for items on order 2?
Thanks!