Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Pivot Tables | Explore Dataset
Introduction to Python for Data Analysis
course content

Зміст курсу

Introduction to Python for Data Analysis

Introduction to Python for Data Analysis

1. Introduction to Python 1/2
2. Introduction to Python 2/2
3. Explore Dataset
4. Becoming an Analyst

Pivot Tables

It's time to deal with a similar function called .pivot_table(). Indeed, it is very similar to .groupby(), but the syntax is different. Here using agg functions is obligatory. If you remember, several chapters ago, we were working with this dataset:

And this example:

Look at the result:

Let's practice, look at the implimentation using .pivot_table() to get the same result:

  • You should put the dataset as the first argument.
  • Put columns on which you want to group the data to the array index; the order is crucial, like in .groupby().
  • Put columns you want to group to the array values(to calculate mean, median, etc.). The order is not crucial. Indeed, this argument is not obligatory; otherwise, aggfunc will be applied for all numerical columns depending on their group.
  • Put NumPy functions that you want to apply to grouped columns to the array aggfunc(to calculate mean, median, etc.); the order is not crucial. One of those that we learned. But use them without brackets and arguments, just the function's title like np.mean() or np.sum().

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Все було зрозуміло?

Секція 3. Розділ 11
toggle bottom row

Pivot Tables

It's time to deal with a similar function called .pivot_table(). Indeed, it is very similar to .groupby(), but the syntax is different. Here using agg functions is obligatory. If you remember, several chapters ago, we were working with this dataset:

And this example:

Look at the result:

Let's practice, look at the implimentation using .pivot_table() to get the same result:

  • You should put the dataset as the first argument.
  • Put columns on which you want to group the data to the array index; the order is crucial, like in .groupby().
  • Put columns you want to group to the array values(to calculate mean, median, etc.). The order is not crucial. Indeed, this argument is not obligatory; otherwise, aggfunc will be applied for all numerical columns depending on their group.
  • Put NumPy functions that you want to apply to grouped columns to the array aggfunc(to calculate mean, median, etc.); the order is not crucial. One of those that we learned. But use them without brackets and arguments, just the function's title like np.mean() or np.sum().

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Все було зрозуміло?

Секція 3. Розділ 11
toggle bottom row

Pivot Tables

It's time to deal with a similar function called .pivot_table(). Indeed, it is very similar to .groupby(), but the syntax is different. Here using agg functions is obligatory. If you remember, several chapters ago, we were working with this dataset:

And this example:

Look at the result:

Let's practice, look at the implimentation using .pivot_table() to get the same result:

  • You should put the dataset as the first argument.
  • Put columns on which you want to group the data to the array index; the order is crucial, like in .groupby().
  • Put columns you want to group to the array values(to calculate mean, median, etc.). The order is not crucial. Indeed, this argument is not obligatory; otherwise, aggfunc will be applied for all numerical columns depending on their group.
  • Put NumPy functions that you want to apply to grouped columns to the array aggfunc(to calculate mean, median, etc.); the order is not crucial. One of those that we learned. But use them without brackets and arguments, just the function's title like np.mean() or np.sum().

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Все було зрозуміло?

It's time to deal with a similar function called .pivot_table(). Indeed, it is very similar to .groupby(), but the syntax is different. Here using agg functions is obligatory. If you remember, several chapters ago, we were working with this dataset:

And this example:

Look at the result:

Let's practice, look at the implimentation using .pivot_table() to get the same result:

  • You should put the dataset as the first argument.
  • Put columns on which you want to group the data to the array index; the order is crucial, like in .groupby().
  • Put columns you want to group to the array values(to calculate mean, median, etc.). The order is not crucial. Indeed, this argument is not obligatory; otherwise, aggfunc will be applied for all numerical columns depending on their group.
  • Put NumPy functions that you want to apply to grouped columns to the array aggfunc(to calculate mean, median, etc.); the order is not crucial. One of those that we learned. But use them without brackets and arguments, just the function's title like np.mean() or np.sum().

Завдання

Your task is to create a pivot table where you will group by plan and count mean and median price. Check, if they vary. Follow the algorithm:

  1. Create a pivot table with the arguments:
  • df as the first argument.
  • 'plan' to the index as the second argument.
  • 'price' to the values as the second argument.
  • np.mean and np.median to the aggfunc as the third argument.
  1. Print the df.

By the way, if they vary significantly, you have outliers (incredibly small or big values).

Секція 3. Розділ 11
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt