Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge | Aggregating and Visualizing Data
Data Manipulation using pandas

book
Challenge

Let's compare mean and median prices for each dwelling type.

Tâche

Swipe to start coding

  1. Group the data in the df dataframe by the values of the 'dtypeh' column.
  2. Select the 'valueh' column.
  3. For each group calculate mean and median (in this order).

Solution

# Importing the library
import pandas as pd

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv')

# Mean and median price for each dwelling type
print(df.groupby('dtypeh')['valueh'].agg(['mean', 'median']))

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2
# Importing the library
import pandas as pd

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv')

# Mean and median price for each dwelling type
print(df.___('___')___.agg(['___', '___']))
toggle bottom row
some-alt