All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.
All our activities include solutions with explanations on how they work and why we chose them.
Suppose you have two dataframes, students
and grades
, with the following structures:
students
Dataframe:student_id | name | age | |
---|---|---|---|
0 | 1 | John Smith | 18 |
1 | 2 | Jane Doe | 17 |
2 | 3 | Sarah Dane | 16 |
grades
Dataframe:student_id | subject | grade | |
---|---|---|---|
0 | 1 | Math | A |
1 | 2 | Science | B |
2 | 4 | English | C |
You want to merge the two dataframes to get the following result:
student_id | name | age | subject | grade | |
---|---|---|---|---|---|
0 | 1 | John Smith | 18 | Math | A |
1 | 2 | Jane Doe | 17 | Science | B |
Suppose you have two dataframes, employees
and departments
, with the following structures:
employees
Dataframe:employee_id | name | department_id | |
---|---|---|---|
0 | 1 | John Smith | 3 |
1 | 2 | Jane Doe | 2 |
2 | 3 | Sarah Dane | 3 |
3 | 4 | Joe Martin | 5 |
departments
Dataframe:department_id | department_name | |
---|---|---|
0 | 2 | Sales |
1 | 3 | Marketing |
2 | 4 | Finance |
You want to merge the two dataframes to get the following result:
employee_id | name | department_id | department_name | |
---|---|---|---|---|
0 | 1 | John Smith | 3 | Marketing |
1 | 3 | Sarah Dane | 3 | Marketing |
2 | 2 | Jane Doe | 2 | Sales |
3 | 4 | Joe Martin | 5 | nan |
4 | nan | nan | 4 | Finance |
Suppose you have two dataframes, df1
and df2
, with the following structures:
df1
Dataframe:left | |
---|---|
0 | foo |
1 | bar |
df2
Dataframe:right | |
---|---|
0 | 7 |
1 | 8 |
You want to merge the two dataframes to get the following result:
left | right | |
---|---|---|
0 | foo | 7 |
1 | foo | 8 |
2 | bar | 7 |
3 | bar | 8 |
Suppose you have two dataframes, df1
and df2
, with the following structures:
df1
Dataframe:ID | Value1 | |
---|---|---|
0 | 2 | 100 |
1 | 3 | 200 |
2 | 1 | 300 |
df2
Dataframe:ID | Value2 | |
---|---|---|
0 | 3 | 400 |
1 | 2 | 500 |
2 | 1 | 600 |
You want to merge the two dataframes to get the following result:
ID | Value1 | Value2 | |
---|---|---|---|
0 | 1 | 300 | 600 |
1 | 2 | 100 | 500 |
2 | 3 | 200 | 400 |