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

book
Challenge

Let's find out the average prices for each pair of number of rooms - number of bedrooms in a dwelling.

Task

Swipe to start coding

  1. Group the values in the df dataframe by values of 'roomh', 'broomh' columns.
  2. Select the 'valueh' column.
  3. Calculate means for each group.

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')

# Grouping and aggregating data
print(df.groupby(['roomh', 'broomh'])['valueh'].mean())

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 7
# 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')

# Grouping and aggregating data
print(df.___([___])___.___())
toggle bottom row
some-alt