I have a data structure that looks like this:
idtenifier amount dist_type new_value new_value2
1 1.0 normal
1 2.0 new_value
1 1.0 new_value2
3 1.0 normal
5 3.0 normal
5 23.0 new_value2
2 1.0 normal
I am looking to get a structure like this:
idtenifier amount dist_type new_value new_value2
1 1.0 normal 2.0 1.0
3 1.0 normal 23.0
5 3.0 normal
2 1.0 normal
I have a feeling the way I am trying to do this is grossly inefficient and I cannot even assign the values in the columns
df['new_value'] = np.nan
for idx, row in df.iterrows():
identifier = row['identifier']
dist_type = row['dist_type']
amount = row['amount']
if idx > 0 and identifier == df.loc[idx-1, 'identifier']:
print(dist_type)
if dist_type == 'new_value':
df.loc[idx-1, 'new_value'] == amount