Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Mean and Median | Aggregate Functions
Introduction to pandas [track]

bookMean and Median

pandas also provides calculations of mean values. To calculate an arithmetic mean (total sum of values/number of values) apply the .mean() method.

What is a median? Assume you sort values in ascending order. Then the middle value of new series is called median. This metric is better in terms of resistance to outliers. To get the median value apply the .median() method. For instance, we can get the average and median prices for all cars with Semi-Auto gear box.

123456789
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Mean price print(df.loc[df.transmission == 'Semi-Auto', 'price'].mean()) # Median price print(df.loc[df.transmission == 'Semi-Auto', 'price'].median())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 6

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 3.33

bookMean and Median

Sveip for å vise menyen

pandas also provides calculations of mean values. To calculate an arithmetic mean (total sum of values/number of values) apply the .mean() method.

What is a median? Assume you sort values in ascending order. Then the middle value of new series is called median. This metric is better in terms of resistance to outliers. To get the median value apply the .median() method. For instance, we can get the average and median prices for all cars with Semi-Auto gear box.

123456789
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Mean price print(df.loc[df.transmission == 'Semi-Auto', 'price'].mean()) # Median price print(df.loc[df.transmission == 'Semi-Auto', 'price'].median())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 6
some-alt