I have data with duplicate parts that looks like this:
Part  |  Location |  ONHand 
A     |  XY       |  5 
A     |  XW       |  4 
B     |  XC       |  6 
B     |  XV       |  8 
C     |  XQ       |  9 
And I'm trying to convert it all into one row per part, listing all the locations and quantities on hand in each location.
I tried using this code
df_f = df.assign(cc=df.groupby('Part').cumcount()+1).set_index(['Part', 'cc']).unstack()
df_f.columns = [f'{col[0]}{col[1]}' for col in df_f.columns]
df_f.to_csv('parts_multi_location.csv')
But the problem is it returns Location 1, 2, 3 and then ONHand 1, 2, 3 and so forth.
I need the end result to return Location 1, Onhand 1, Location 2, Onhand 2, so the headers should look like this:
Part | Location_1 | Onhand_1 | Location 2| Onhand 2
A    | XY         |   5      | XW        | 4
B    | XC         |   6      | XV        | 8
C    | XQ         |   9
 
     
    