I’m totally stuck with a task on using groupby in a dataframe.
I have the following df in a csv file 'athletes.csv:
The task is to call (and print) from a main function another function which takes three attributes:
- The dataframe df
- The age 15
- The mean value for all events (100m,200m,400m,800m,1500m)) for the age 15
The function should be grouped by gender and should reset the index.
The output should be like the below.
# function to groupby def age_statistics(df,age,mean): # no idea how to build it aggregated_dataframe = aggregated_dataframe.reset_index(drop=False) return aggregated_dataframe # main function def main(filename='athletes.csv'): df = pd.read_csv(filename, index_col=0) df['100m'] = df['100m'].astype(float) df['200m'] = df['200m'].astype(float) df['400m'] = df['400m'].astype(float) df['800m'] = df['800m'].astype(float) df['1500m'] = df['1500m'].astype(float) print(age_statistics(df,15,'mean')) # Do not edit this if __name__ == "__main__": main()
Anybody can help with that?