Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Calculating Mean and Median Values with Python | Mean, Median and Mode with Python
Learning Statistics with Python
course content

Course Content

Learning Statistics with Python

Learning Statistics with Python

1. Basic Concepts
2. Mean, Median and Mode with Python
3. Variance and Standard Deviation
4. Covariance vs Correlation
5. Confidence Interval
6. Statistical Testing

bookCalculating Mean and Median Values with Python

You're already familiar with the mean and median, but now let's calculate them using Python. To do this, we need to import the NumPy library with the np alias.

Let's begin by importing the library:

We will use the .mean() and .median() functions to calculate the mean and median values, respectively. Here's a code example, feel free to modify the columns and observe the results:

12345678910111213
# Import library import numpy as np 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) # Calculate the mean value mean = np.mean(df['salary_in_usd']) # Calculate the median value median = np.median(df['salary_in_usd']) print('The mean value is', mean) print('The median value is', median)
copy

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2
We're sorry to hear that something went wrong. What happened?
some-alt