I want to combine 2 dataframes. I have tried several methods but not sure how I can achieve the final dataframe. Appreciate any advice on how can i do this.
data_list_1 = [['Employee', 'Course Name', 'Status'],
['Abel', "Course_A", "Completed"],
['Bain', "Course_A", "Incomplete"]]
data_list_2 = [['Employee', 'Course Name', 'Lesson Name', 'Lesson Score', 'Status'],
['Abel', 'Course_B', 'Lesson_1', 100, ""],
['Abel', 'Course_B', 'Lesson_2', 100, ""],
['Abel', 'Course_B', 'Lesson_3', 100, ""],
['Abel', 'Course_B', 'Lesson_4', 100, ""],
['Bain', 'Course_B', 'Lesson_1', 100, ""],
['Bain', 'Course_B', 'Lesson_2', 100, ""],
['Coot', 'Course_B', 'Lesson_1', 100, ""],
['Coot', 'Course_B', 'Lesson_2', 100, ""],
['Coot', 'Course_B', 'Lesson_3', 100, ""],
['Coot', 'Course_B', 'Lesson_4', 100, ""],
['Coot', 'Course_B', 'Lesson_5', 100, ""]]
Course_A_df = pd.DataFrame(data_list_1[1:], columns = data_list_1[0])
Course_B_df = pd.DataFrame(data_list_2[1:], columns = data_list_2[0])
I want to have the following dataframe to use it in Tableau for visualisation purpose. Basically the final df should also have Coot with None values and for Course_B Status to be completed if all 5 Lesson score is 100.
to_achieved = [['Employee', 'Course Name', 'Lesson Name', 'Lesson Score', 'Status'],
['Abel', "Course_A", None, None, "Completed"],
['Bain', "Course_A", None, None, "Incomplete"],
['Coot', "Course_A", None, None, None],
['Abel', 'Course_B', 'Lesson_1', 100, "Incomplete"],
['Abel', 'Course_B', 'Lesson_2', 100, "Incomplete"],
['Abel', 'Course_B', 'Lesson_3', 100, "Incomplete"],
['Abel', 'Course_B', 'Lesson_4', 100, "Incomplete"],
['Bain', 'Course_B', 'Lesson_1', 100, "Incomplete"],
['Bain', 'Course_B', 'Lesson_2', 100, "Incomplete"],
['Coot', 'Course_B', 'Lesson_1', 100, "Completed"],
['Coot', 'Course_B', 'Lesson_2', 100, "Completed"],
['Coot', 'Course_B', 'Lesson_3', 100, "Completed"],
['Coot', 'Course_B', 'Lesson_4', 100, "Completed"],
['Coot', 'Course_B', 'Lesson_5', 100, "Completed"]]
to_achieved_df = pd.DataFrame(to_achieved[1:], columns = to_achieved[0])
to_achieved_df
I have tried concat and merge but it doesn't seems to give me what i want.
df_concat = pd.concat([Course_A_df, Course_B_df], axis=0, ignore_index=True)
df_concat
merged = pd.merge(left=Course_A_df, right=Course_B_df, left_on='Employee', right_on='Employee', how='left')
merged
For the calculation of status, i have tried groupby, but is that any way i can check if the value is 500 and update the status?
Thank you!