Python Forum
Finding Max and Min Values Associated with Unique Identifiers in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Max and Min Values Associated with Unique Identifiers in Python
#1
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]
Reply
#2
df['ID_Max']= df.groupby(['ID'])['N1'].transform(max)
df['ID_Min']= df.groupby(['ID'])['N1'].transform(min)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 220 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  5 variants to invert dictionaries with non-unique values Drakax1 2 2,562 Aug-31-2020, 11:40 AM
Last Post: snippsat
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 4,235 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Getting Unique values from LISTS aankrose 2 2,210 Oct-17-2019, 05:33 PM
Last Post: aankrose
  Finding nearest point of a Multidigraph in Python 3.7 stixmagiggins 5 3,659 Aug-24-2019, 08:51 AM
Last Post: ThomasL
  Help with finding correct topic in Python learning yahya01 1 2,168 Jun-06-2019, 05:01 PM
Last Post: buran
  getting unique values and counting amounts Truman 26 9,911 Mar-15-2019, 12:44 AM
Last Post: Truman
  finding problems connecting python to sqlite Dennis 1 2,259 Dec-10-2018, 02:58 PM
Last Post: Larz60+
  finding 2 max values in an array in python Akankshha 11 169,279 Oct-18-2018, 09:16 AM
Last Post: perfringo
  finding own python source file to read it Skaperen 3 2,972 Aug-27-2018, 11:23 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020