After calculating the means for all the records per event type, I now must calculate the number of times an athlete has scored above the mean. I have found a way to do this 1 at a time but I would like to know if there is a more elegant way of doing it in pandas. Sorry for the images but it probably the best way I can show you guys what I have done and want to do
EDIT: My apologies, I am new to the interface. I will try to be as clear as possible with code.(Anyone know of a better way to display a dataframe thats is not an image for stackoverflow purposes?
d = {'Event':['Mens 100m','Womens 100m','Mens 800m', 'Mens 800m'],'Record':[10.06,10.6,50.4,60.5]}
df = pd.DataFrame(data = d)
1.) I needed to find the means the records set for all the different events:
for i in range(len(Events)):
x = df[df['Event'] == Events[i]]['Record'].mean()
print(Events[i], ":", "{0:.5f}".format(x))
#The line below gives me a list of all the means per different type of event using a list comp.
Means = [df[df['Event']== Events[i]]['Record'].mean() for i in range(len(Events))]
2.) Using these means I must find the number of athletes for each event that have a record above the mean that was calculated in the line above.
# i = 0 where Events[0] is 'Womens 100m'
i = 0; df[df['Event'] == Events[i]][['Record']] > Means[i]
Output:2
I need to count the number of True values in the above for all events. Any nice way to do this except for assigning it as a series and then counting True? Which would look like this:
d = {'Athletes over Mean for Each Event':[4,6,10,2,5,6]}
df = pd.DataFrame(data = d)
Thank you again in advance, hope I made it clearer this time.