0

I have this dataset

Part# Location  picks
A     xy        34
A     xc        35
A     er        3
A     qw        2
B     xf        33
B     gh        21
C     po        11
C     re        12
C     wq        2

But i want to convert all duplicate rows based off Part# into a single row where the different locations and respective picks will show up as:

Part#  Location1    picks1  Location2   picks2  Location3   picks3  Location4   picks4  
A      xy        34      xc          35      er          3       qw          2
B      xf        33      gh          21
C      po        11      re          12      wq          2

The data set is huge so the duplicates can end up being more than four.

ricsilo
  • 105
  • 1
  • 9
  • Look at Question 10 in the dup link. – Quang Hoang Apr 21 '20 at 21:31
  • I have looked at it, but most of these are either fixed value columns, or a column generates for each unique value within the particular column itself. I want to have generic column names (loc1 loc2 loc3) where each successive location gets stored in the next empty column ... Look at my question and desired result and you will see that what i'm looking for is particularly different – ricsilo Apr 21 '20 at 21:41
  • I had tried that before, but again, it doesn't work because it assigns a new column with the location name attached, for example, i ended up with 320+ columns. I shouldn't have more than 6 columns or something similar. Each location is going to be different and only the part numbers are repeating – ricsilo Apr 21 '20 at 21:48
  • I had tried that actually, followed with `df_f.columns = [f'{col[0]}{col[1]}' for col in df_f.columns]` but it still gave me 320 columns – ricsilo Apr 21 '20 at 22:02
  • 1
    Oh man you are absolutely correct! Hidden within the actual data set there is an extensive duplicate! Thanks so much – ricsilo Apr 21 '20 at 22:17

0 Answers0