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

book
Creating a Pivot Table

Tarea

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.

Solución

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

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 6
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))

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt