Q. A dataframe Stu stores details like 'Name', 'Class', 'Subject_Id' for 10 students and another dataframe Marks stores details like 'Subject_Id' and 'Avgmarks'. Write code so that two dataframes merge data on the basis of common Subject id.


Answer =




import pandas as pd
import numpy as np

Stu = pd.DataFrame( { "Name" : [ "Name1", "Name2", "Name3", "Name4", \
                            "Name6", "Name7", "Name8", "Name9", \
                            "Name10", "Name11" ], "Class" : [ 11, 7, 6, 1, 10, 7, 11, 12, 8, 10 ], \
                    "Subject_Id" : [ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ] } )

Marks = pd.DataFrame( { "Subject_Id" : [16, 25, 21, 15, 18, 14, 10, 60, 19, 11], \
                      "Avgmarks":[11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ] } )

print( pd.merge(Stu, Marks, on = "Subject_Id" ) )



Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post