Python Forum
Get max values based on unique values in another list - python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get max values based on unique values in another list - python
#9
One last note here as I have been experimenting with pandas since Volcano pointed us in that direction.
https://pandas.pydata.org/pandas-docs/st...ggregation

It is designed such that you don't even need the loop to apply functions to the dataframe:
df = pd.DataFrame(x)
print(df.groupby(df[0]).agg(max))
Output:
1 0 126.0 23.0 129.0 125.0 132.0 41.0 142.0 76.0
In fact you can apply multiple functions in one operation and it even names the columns for you automatically:
df = pd.DataFrame(x)
print(df.groupby(df[0]).agg([max, min, sum, np.mean]))
Output:
1 max min sum mean 0 126.0 23.0 1.0 53.0 8.833333 129.0 125.0 1.0 293.0 36.625000 132.0 41.0 1.0 44.0 14.666667 142.0 76.0 6.0 82.0 41.000000
Reply


Messages In This Thread
RE: Get max values based on unique values in another list - python - by Mekire - Jun-12-2018, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assigning conditional values in Pandas Scott 3 1,027 Dec-19-2023, 03:10 AM
Last Post: Larz60+
  attempt to split values from within a dataframe column mbrown009 8 2,582 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 938 Dec-12-2022, 03:22 AM
Last Post: ill8
  Increase df column values decimals SriRajesh 2 1,170 Nov-14-2022, 05:20 PM
Last Post: deanhystad
  replace sets of values in an array without using loops paul18fr 7 1,868 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  Changing Values in a List DaveG 1 1,341 Apr-04-2022, 03:38 PM
Last Post: jefsummers
Question How does one clean a populated table in MySQL/MariaDB? Copying values across tables? BrandonKastning 2 1,630 Jan-17-2022, 05:46 AM
Last Post: BrandonKastning
  Matplotlib scatter plot in loop with None values ivan_sc 1 2,348 Nov-04-2021, 11:25 PM
Last Post: jefsummers
  pandas: Compute the % of the unique values in a column JaneTan 1 1,848 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  Write a dictionary with arrays as values into JSON format paul18fr 3 5,932 Oct-20-2021, 10:38 AM
Last Post: buran

Forum Jump:

User Panel Messages

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