Course Content
Learning Statistics with Python
Learning Statistics with Python
Statistics with pandas
The Pandas library already has three built-in functions for calculating the mean and median. To import Pandas, use the following syntax:
Here's an example of calculating the mean and median for the 'work_year'
column in the dataset named df
.
Feel free to change the columns and observe the results:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/update/ds_salaries_statistics', index_col = 0) # Calculating the mean value mean = df['work_year'].mean() # Calculating the median value median = df['work_year'].median() print('The mean value is', mean) print('The median value is', median)
You see, to calculate all the important statistical values, we need to apply methods that handle the measurements:
Thanks for your feedback!