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

book
Calculating Mean and Median Values with Python

You're already familiar with the mean and median. Now it's time to calculate them using Python. Start by importing the numpy library using the np alias:

python
import numpy as np

Use the .mean() and .median() functions to compute the mean and median values. Here's a code example, feel free to modify the columns and observe the results:

# 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)
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
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt