Published On May 6, 2022
How to compute the mean of a list and the columns of a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/calculate...
Python code of this video:
my_list = [1, 4, 6, 1, 3, 1, 4, 5] # Create example list
print(my_list) # Print example list
import numpy as np # Load NumPy
print(np.mean(my_list)) # Get mean of list
import pandas as pd # Import pandas library in Python
data = pd.DataFrame({'x1':[6, 2, 7, 5, 3, 7, 2, 7, 9], # Create pandas DataFrame
'x2':range(0, 9),
'group':['A', 'B', 'B', 'A', 'A', 'C', 'C', 'B', 'A']})
print(data) # Print pandas DataFrame
print(data['x1'].mean()) # Get mean of one column
print(data.mean(numeric_only = True, axis = 1)) # Get mean of rows
print(data.mean(axis = 1)) # Get mean of rows
print(data.groupby('group').mean()) # Get mean by group
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – Group for Discussions & Questions: / statisticsglobe
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – Group for Discussions & Questions: / 12555223
Twitter: / joachimschork
Music by bensound.com