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

Contenido del Curso

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

Visualization: First Steps

An essential tool for Data Analysts is visualization. The first one here is .barplot(). To use the tools you need to import the libraries, look at the syntax:

  • import matplotlib.pyplot as plt
  • import seaborn as sns

We will use the second one, Seaborn, but it is based on Matplotlib, so we need to import two of them. Look at the dataset that we used to use for examples:

Our task is to visualize experience_level and the mean salary for each of them. Look at the code:

Here, is the output

barplot

Look at the sixth line of code:

df = df[['experience_level', 'salary']].groupby(['experience_level']).median().reset_index()

Here you can recognize the new function .reset_index(). It is easy and just transforms the result of .groupby() function into the regular dataset. Look at the pictures (the first one is before and the second one is after):

Then we will move to the seventh line of code.

sns.barplot(data = df, x = 'experience_level', y = 'salary')

  • sns - referring to seaborn library.
  • barplot the type of plot.
  • data = df the DataFrame.
  • x = 'experience_level' the column for x-axis.
  • y = 'salary' the column for y-axis.

Move to the eighth line of code:

plt.show()

Function from the matplotlib library to output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

¿Todo estuvo claro?

Sección 3. Capítulo 16
toggle bottom row

Visualization: First Steps

An essential tool for Data Analysts is visualization. The first one here is .barplot(). To use the tools you need to import the libraries, look at the syntax:

  • import matplotlib.pyplot as plt
  • import seaborn as sns

We will use the second one, Seaborn, but it is based on Matplotlib, so we need to import two of them. Look at the dataset that we used to use for examples:

Our task is to visualize experience_level and the mean salary for each of them. Look at the code:

Here, is the output

barplot

Look at the sixth line of code:

df = df[['experience_level', 'salary']].groupby(['experience_level']).median().reset_index()

Here you can recognize the new function .reset_index(). It is easy and just transforms the result of .groupby() function into the regular dataset. Look at the pictures (the first one is before and the second one is after):

Then we will move to the seventh line of code.

sns.barplot(data = df, x = 'experience_level', y = 'salary')

  • sns - referring to seaborn library.
  • barplot the type of plot.
  • data = df the DataFrame.
  • x = 'experience_level' the column for x-axis.
  • y = 'salary' the column for y-axis.

Move to the eighth line of code:

plt.show()

Function from the matplotlib library to output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

¿Todo estuvo claro?

Sección 3. Capítulo 16
toggle bottom row

Visualization: First Steps

An essential tool for Data Analysts is visualization. The first one here is .barplot(). To use the tools you need to import the libraries, look at the syntax:

  • import matplotlib.pyplot as plt
  • import seaborn as sns

We will use the second one, Seaborn, but it is based on Matplotlib, so we need to import two of them. Look at the dataset that we used to use for examples:

Our task is to visualize experience_level and the mean salary for each of them. Look at the code:

Here, is the output

barplot

Look at the sixth line of code:

df = df[['experience_level', 'salary']].groupby(['experience_level']).median().reset_index()

Here you can recognize the new function .reset_index(). It is easy and just transforms the result of .groupby() function into the regular dataset. Look at the pictures (the first one is before and the second one is after):

Then we will move to the seventh line of code.

sns.barplot(data = df, x = 'experience_level', y = 'salary')

  • sns - referring to seaborn library.
  • barplot the type of plot.
  • data = df the DataFrame.
  • x = 'experience_level' the column for x-axis.
  • y = 'salary' the column for y-axis.

Move to the eighth line of code:

plt.show()

Function from the matplotlib library to output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

¿Todo estuvo claro?

An essential tool for Data Analysts is visualization. The first one here is .barplot(). To use the tools you need to import the libraries, look at the syntax:

  • import matplotlib.pyplot as plt
  • import seaborn as sns

We will use the second one, Seaborn, but it is based on Matplotlib, so we need to import two of them. Look at the dataset that we used to use for examples:

Our task is to visualize experience_level and the mean salary for each of them. Look at the code:

Here, is the output

barplot

Look at the sixth line of code:

df = df[['experience_level', 'salary']].groupby(['experience_level']).median().reset_index()

Here you can recognize the new function .reset_index(). It is easy and just transforms the result of .groupby() function into the regular dataset. Look at the pictures (the first one is before and the second one is after):

Then we will move to the seventh line of code.

sns.barplot(data = df, x = 'experience_level', y = 'salary')

  • sns - referring to seaborn library.
  • barplot the type of plot.
  • data = df the DataFrame.
  • x = 'experience_level' the column for x-axis.
  • y = 'salary' the column for y-axis.

Move to the eighth line of code:

plt.show()

Function from the matplotlib library to output the plot.

Tarea

Visualize the sum of money you receive from users depending on their subscription plan.

  1. Import the seaborn with the sns alias.
  2. Import the matplotlib.pyplot with the plt alias.
  3. Prepare data for visualization using the .groupby() function:
  • Extract columns 'plan', 'price'.
  • Group by column plan.
  • Calculate the sum of all prices for each plan.
  • Reset indices.
  1. Create the barplot using the seaborn:
  • Use df as the data argument
  • Use the 'plan' column for the x-axis
  • Use the 'price' column for the y-axis.
  1. Output the plot.

Sección 3. Capítulo 16
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt