Contenido del Curso
Introduction to Python for Data Analysis
Introduction to Python for Data Analysis
Group Data 2.0
Let's imagine the situation where you want to group by job_title
, but then you want to group by experience_level
, for example.
Here, everything is so simple you need just put several columns in needed order to groupby function:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df.groupby(['job_title', 'experience_level']).mean() print(df)
Look at the output.
By the way, if you don't want to group the whole table, you can specify the name of columns for which we should apply grouping. For instance, look at the previous code. If we want to calculate the mean value only for the 'salary'
column, we specify needed columns, but do not forget about columns that should be grouped:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df[['salary','job_title', 'experience_level']].groupby(['job_title', 'experience_level']).mean() print(df)
Be careful; if you want to work with several columns, you have to put them into [[]]
(look at the example).
Look at the result:
Tarea
Your task here is to work with the known dataset and count amount of users for each plan depending on the status of their trial. To do it, follow the algorithm:
- Group by
'plan'
column, then by'trial'
column, using only three columns:'user_id', 'plan', 'trial'
. Apply thecount()
function. - Print the
df
using onlyprint()
function.
¡Gracias por tus comentarios!
Group Data 2.0
Let's imagine the situation where you want to group by job_title
, but then you want to group by experience_level
, for example.
Here, everything is so simple you need just put several columns in needed order to groupby function:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df.groupby(['job_title', 'experience_level']).mean() print(df)
Look at the output.
By the way, if you don't want to group the whole table, you can specify the name of columns for which we should apply grouping. For instance, look at the previous code. If we want to calculate the mean value only for the 'salary'
column, we specify needed columns, but do not forget about columns that should be grouped:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df[['salary','job_title', 'experience_level']].groupby(['job_title', 'experience_level']).mean() print(df)
Be careful; if you want to work with several columns, you have to put them into [[]]
(look at the example).
Look at the result:
Tarea
Your task here is to work with the known dataset and count amount of users for each plan depending on the status of their trial. To do it, follow the algorithm:
- Group by
'plan'
column, then by'trial'
column, using only three columns:'user_id', 'plan', 'trial'
. Apply thecount()
function. - Print the
df
using onlyprint()
function.
¡Gracias por tus comentarios!
Group Data 2.0
Let's imagine the situation where you want to group by job_title
, but then you want to group by experience_level
, for example.
Here, everything is so simple you need just put several columns in needed order to groupby function:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df.groupby(['job_title', 'experience_level']).mean() print(df)
Look at the output.
By the way, if you don't want to group the whole table, you can specify the name of columns for which we should apply grouping. For instance, look at the previous code. If we want to calculate the mean value only for the 'salary'
column, we specify needed columns, but do not forget about columns that should be grouped:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df[['salary','job_title', 'experience_level']].groupby(['job_title', 'experience_level']).mean() print(df)
Be careful; if you want to work with several columns, you have to put them into [[]]
(look at the example).
Look at the result:
Tarea
Your task here is to work with the known dataset and count amount of users for each plan depending on the status of their trial. To do it, follow the algorithm:
- Group by
'plan'
column, then by'trial'
column, using only three columns:'user_id', 'plan', 'trial'
. Apply thecount()
function. - Print the
df
using onlyprint()
function.
¡Gracias por tus comentarios!
Let's imagine the situation where you want to group by job_title
, but then you want to group by experience_level
, for example.
Here, everything is so simple you need just put several columns in needed order to groupby function:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df.groupby(['job_title', 'experience_level']).mean() print(df)
Look at the output.
By the way, if you don't want to group the whole table, you can specify the name of columns for which we should apply grouping. For instance, look at the previous code. If we want to calculate the mean value only for the 'salary'
column, we specify needed columns, but do not forget about columns that should be grouped:
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/INTRO+to+Python/ds_salaries.csv', index_col = 0) df = df[['salary','job_title', 'experience_level']].groupby(['job_title', 'experience_level']).mean() print(df)
Be careful; if you want to work with several columns, you have to put them into [[]]
(look at the example).
Look at the result:
Tarea
Your task here is to work with the known dataset and count amount of users for each plan depending on the status of their trial. To do it, follow the algorithm:
- Group by
'plan'
column, then by'trial'
column, using only three columns:'user_id', 'plan', 'trial'
. Apply thecount()
function. - Print the
df
using onlyprint()
function.