Python Forum

Full Version: Finding Max and Min Values Associated with Unique Identifiers in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need help to edit my Python code below - to search the ID column and then give the max and min values for each ID and write them into 2 new columns. I tried the code below but I don't know how to write the min and max values in new columns labelled ID_Min and ID Max

Python code:
for column, value in df.ID():
     ID_max = df.groupby(['ID'])['N1'].max()
     ID_min = df.groupby(['ID'])['N1'].min()
Screenshot of my table:
[Image: 9TxI8.png]
df['ID_Max']= df.groupby(['ID'])['N1'].transform(max)
df['ID_Min']= df.groupby(['ID'])['N1'].transform(min)