I'd like to use a loop to change the function applied to a DataFrame and name the output in python
For example, I would like to calculate the mean, max,sum, min, etc of the same DataFrame and I'd like to use a loop to cycle through these and name the output.
Say i have a DataFrame df ...
numbs = [[ 1,2,4],[34,5,6],[22,4,5]]
df = pd.DataFrame(numbs,columns=['A','B','C'])
I want to use this calcs dict to define the function applied to df and name the output, like this
calcs = {'sum','mean','max'}
for i in calcs:
('df'+ i) = df.i
And I was looking for output like
dfsum
A 57
B 11
C 15
dfmean
A 19.000
B 3.667
C 5.000
etc