Bottom Page

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:
İmage
Larz60+ wrote May-08-2020, 03:21 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
df['ID_Max']= df.groupby(['ID'])['N1'].transform(max)
df['ID_Min']= df.groupby(['ID'])['N1'].transform(min)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 452 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Getting Unique values from LISTS aankrose 2 429 Oct-17-2019, 05:33 PM
Last Post: aankrose
  getting unique values and counting amounts Truman 26 2,538 Mar-15-2019, 12:44 AM
Last Post: Truman
  finding 2 max values in an array in python Akankshha 11 2,071 Oct-18-2018, 09:16 AM
Last Post: perfringo
  count unique values of a list with a list 3Pinter 2 2,565 Jul-05-2018, 11:52 AM
Last Post: 3Pinter
  Need help for finding cumulative values in a loop Lightning1800 10 1,933 May-23-2018, 07:48 PM
Last Post: Lightning1800
  Finding all maximum values in a matrix Lightning1800 3 1,240 May-14-2018, 03:55 PM
Last Post: Lightning1800
  Finding values to draw a line on a curve kesenthilkumar 2 1,389 Sep-19-2017, 09:50 AM
Last Post: kesenthilkumar

Forum Jump:


Users browsing this thread: 1 Guest(s)