Np.mean() vs. datafram.column.mean()


What is difference between?: np.mean(column_name) and dataframe.column_name.mean()
Maybe the syntax is not correct. But my question really is why use np.mean() instead of df.mean()?


There’s nothing particularly wrong with either of them. You could pick whatever you feel is most readable but I’d note that by and large if you can use a method of an array e.g. .mean() they tend to be a little faster. The numpy function can however take a much wider array of input, e.g. you can call it on things other than arrays, e.g. built-in sequences like lists so it’s still a useful function, just not essential in the context you mention.


Oh cool. Thank you so much!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.