So I have a Data Frame for which there is the same ID contains multiple Custom Fields. I found this question but it's not quite what I am looking for. Code to create desired starter data frame below
df = pd.DataFrame()
df['ID'] = [np.random.randint(1,2000) for x in range(0,1000)]
new = pd.DataFrame()
for x in range(0,10):
new = new.append(df)
new = new.sort_values('ID').reset_index(drop=True)
new['Custom Field'] = [np.random.randint(1,20) for x in new['ID']]
new['Value'] = [np.random.randint(0,10000000) for x in new['ID']]
new = new.groupby(['ID','Custom Field']).first().reset_index()
new = new.sort_values(['ID','Custom Field']).reset_index(drop=True)
new.head()
Essentially the below picture is what I am looking for:
This image shows that it's taking the values in the Custom Field table and transposing them into separate columns. For every ID it can have up to 20 values in the Custom Field table. I need each of the custom field values (1-20) to be in their own column. If a certain ID does not have the value, it will be blank. I am trying to be as specific as possible but it's hard to explain. Let me know if I need to edit the question to provide more detail.