Sunday, 21 August 2022

Pandas - Calculate the Average of the Same data

I have a pandas df that has a list of item numbers and then a number next to it. I would like to somehow get the average of all the same item numbers and that number next to it.

Here is a part of the DataFrame:

Item ID        Time
X32TR2639      7.142857
X32TR2639      7.142857
X36SL7708      16.714286
X36TA0029      16.714286
X36TR3016      16.714286

Desired output:

Item ID        Average Time:
X32TR2639      7.142857
X36SL7708      16.714286
X36TA0029      16.714286
X36TR3016      16.714286

I would like for each item ID there is to have an average time however if there is more than one copy of that Item ID take the average of them all

This is only a small part of the dataframe. As you see the first two are the same. I would like to calculate the average of all of them. So if its the same use all those numbers and get that average. So the script would look for all of the item numbers X32TR2639 and get the number next to it and then get that average.



from Pandas - Calculate the Average of the Same data

No comments:

Post a Comment