Python Forum
Finding Max and Min Values Associated with Unique Identifiers in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Finding Max and Min Values Associated with Unique Identifiers in Python (/thread-26644.html)



Finding Max and Min Values Associated with Unique Identifiers in Python - ubk046 - May-08-2020

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]


RE: Finding Max and Min Values Associated with Unique Identifiers in Python - anbu23 - May-08-2020

df['ID_Max']= df.groupby(['ID'])['N1'].transform(max)
df['ID_Min']= df.groupby(['ID'])['N1'].transform(min)