Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Creating a Pivot Table | Aggregating Data
Advanced Techniques in pandas

book
Creating a Pivot Table

Taak

Swipe to start coding

Your task here is to practice using pivot tables. Depending on the airline and the airport from which the flight started, calculate the number of delays and the minimum and maximum length of the flight. Follow the algorithm:

Create a pivot table:

  • Assign the columns 'Airline' and 'AirportFrom' to the index argument;
  • Assign the columns 'Delay' and 'Length' to the values argument (in this order);
  • Using the aggfunc argument, find the minimum and maximum of the 'Length', and count the number of values in the 'Delay' column.

Oplossing

import pandas as pd

data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/plane', index_col = 0)

# Create pivot table
data = pd.pivot_table(data, index = ['Airline', 'AirportFrom'],
values = ['Delay', 'Length'],
aggfunc = {'Length': ['min', 'max'], 'Delay': 'count'})

print(data.head(10))

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 6
single

single

import pandas as pd

data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/plane', index_col = 0)

# Create pivot table
data = pd.pivot_table(data, index = ___,
values = [___],
aggfunc = {'___': [___, ___], '___': '___'})

print(data.head(10))

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt