Reputation: 605
I want to apply multiple statistics functions like mean, median, variance etc. on a particular column of a data frame. I used following code. It produced results but not in required manner. Please tell me how i can write such kind of functions.
def summary(x):
output1=x["Close"].mean
output2=x["Close"].median
output=(output1,output2)
return output
summary(infy)
required_output=(mean,median)
Upvotes: 2
Views: 36
Reputation: 1824
It's because you need to call the mean and median methods:
x["Close"].mean() # Note the brackets
x["Close"].median()
But as others have stated, pandas has a nice built-in agg
for this task.
Upvotes: 0
Reputation: 409
I think your code is missing braces. Apply this chunk of code.
def summary(x):
output1=x["Close"].mean()
output2=x["Close"].median()
output=(output1,output2)
return output
summary(infy)
Upvotes: 1